Sunday, October 16, 2011

EF Query Parsing


The following table lists the time in milliseconds to execute with the NwindOrdersEdmCS.sln (or VB)
project cached Entity SQL and T - SQL queries that return the same amount of data. It ’ s reasonable for
Entity SQL queries to be slower to execute than T - SQL Queries, because T - SQL doesn ’ t require creating
and translating the CQT or handling hierarchical resultsets.
380

Text without Order Details 10 ms. 7 ms.
XML without Order Details 17 ms. 11 ms.
Text with Order Details 27 ms. 17 ms.
XML with Order Details 42 ms. 21 ms.
 
Entity SQL from ecmdNwind.CommandText

SELECT o, o.Order_Details FROM NorthwindEntities.Orders AS o
WHERE o.ShipCountry = @Country ORDER BY o.OrderDate DESC

T - SQL from ToTraceString()

SELECT
[Project1].[OrderID] AS [OrderID],
[Project1].[CustomerID] AS [CustomerID],
[Project1].[EmployeeID] AS [EmployeeID],
[Project1].[OrderDate] AS [OrderDate],
[Project1].[RequiredDate] AS [RequiredDate],
[Project1].[ShippedDate] AS [ShippedDate],
[Project1].[ShipVia] AS [ShipVia],
[Project1].[Freight] AS [Freight],
[Project1].[ShipName] AS [ShipName],
[Project1].[ShipAddress] AS [ShipAddress],
[Project1].[ShipCity] AS [ShipCity],
[Project1].[ShipRegion] AS [ShipRegion],
[Project1].[ShipPostalCode] AS [ShipPostalCode],
[Project1].[ShipCountry] AS [ShipCountry],
[Project1].[C1] AS [C1],
[Project1].[C2] AS [C2],
[Project1].[OrderID1] AS [OrderID1],
[Project1].[ProductID] AS [ProductID],
[Project1].[UnitPrice] AS [UnitPrice],
[Project1].[Quantity] AS [Quantity],
[Project1].[Discount] AS [Discount]
FROM ( SELECT
[Extent1].[OrderID] AS [OrderID],
[Extent1].[CustomerID] AS [CustomerID],
[Extent1].[EmployeeID] AS [EmployeeID],
[Extent1].[OrderDate] AS [OrderDate],
[Extent1].[RequiredDate] AS [RequiredDate],
[Extent1].[ShippedDate] AS [ShippedDate],
[Extent1].[ShipVia] AS [ShipVia],
[Extent1].[Freight] AS [Freight],
[Extent1].[ShipName] AS [ShipName],
[Extent1].[ShipAddress] AS [ShipAddress],
[Extent1].[ShipCity] AS [ShipCity],
381
[Extent1].[ShipRegion] AS [ShipRegion],
[Extent1].[ShipPostalCode] AS [ShipPostalCode],
[Extent1].[ShipCountry] AS [ShipCountry],
1 AS [C1],
[Extent2].[OrderID] AS [OrderID1],
[Extent2].[ProductID] AS [ProductID],
[Extent2].[UnitPrice] AS [UnitPrice],
[Extent2].[Quantity] AS [Quantity],
[Extent2].[Discount] AS [Discount],
CASE WHEN ([Extent2].[OrderID] IS NULL) THEN CAST(NULL AS int)
ELSE 1 END AS [C2]
FROM [dbo].[Orders] AS [Extent1]
LEFT OUTER JOIN [dbo].[Order Details] AS [Extent2]
ON [Extent1].[OrderID] = [Extent2].[OrderID]
WHERE [Extent1].[ShipCountry] = @Country
) AS [Project1]
ORDER BY [Project1].[OrderDate] DESC, [Project1].[OrderID] ASC, [Project1].[C2] ASC
Executing the preceding batch in SQL Server Management Studio sends an extraordinarily long
statement to generate a conventional LEFT OUTER JOIN that ’ s the same as ordinarily generated by:
T - SQL
SELECT o.*, d.*
FROM Orders AS o LEFT OUTER JOIN [Order Details] AS d ON d.OrderID = o.OrderID
WHERE ShipCountry = ‘USA’
ORDER BY o.OrderID DESC

Saturday, October 15, 2011

Entity - Relationship and EDM Terminology


Entity - Relationship and EDM Terminology

EF is the heir apparent to DataSet s as Microsoft ’ s preferred relational data management architecture. EF
is much more than a conventional object/relational mapping (O/RM) tool. EF maps the schema of an
underlying relational database to an Entity Data Model (EDM), which is based on Dr. Peter Chen ’ s Entity-
Relationship (E - R) model. Like ObjectSpaces, three XML files define the physical (relational), mapping and
conceptual (E - R) schemas of layers to make the transformation from the relational model to the EDM. An
SQL- like language called Entity SQL (also called eSQL) queries the EDM ’ s mapping provider and returns to
the DbDataReader a collection of DbDataRecord s by default. An Object Services layer enables Entity
SQL queries against ObjectQuery instances to return IQueryable collections of entities ( EntitySet s)
or anonymous types instead of DbDataRecord s. Substituting LINQ to Entities for Entity SQL queries
against ObjectQuery instances is an alternative method for returning EntitySet s or anonymous types.

Entities are “ things ” that can be distinctly identified, such as persons, organizations and events.
Documents representing objects, such as deeds, and transactions, sales orders, purchase orders,
invoices, and line items also are entities. EDM refers to entities as EntityType s, which the EF
documentation describes as “ abstract specifications for the details of a data structure in the
application domain. ” EDM uses table names for EntityType names, but the singular form is
preferred; fortunately, editing EntityType names in the graphical EDM Designer is easy.
Entity sets classify (contain) entities with common properties. EDM ’ s EntitySet s contain
EntityType s of the same type or a subtype. It ’ s a common practice to name EDM EntitySet s
with plural of the EntityType ; Dr. Chen uses the singular form. An EDM EntityContainer
represents a database, which is a collection of EntitySet s.
Entity primary keys uniquely identify each entity in an entity set. An entity primary key, which
EDM calls a Key , Key attribute , or Key value , may be a natural (semantically meaningful) or
surrogate (artificial) key, such as an auto - incrementing int identity or ROWGUIDCOL column.
Relationships represent associations between entities, which EDM calls Association s. Most
Association s are binary (between two different entities), but unary (between different
members of the same entity, such as an Employee who reports to another Employee as his or
her manager) and ternary (between three entities, such as Supplier - Product - OrderItem ).
Relationship sets are tuples of relationships. The mathematic definition of tuple is an ordered list of
objects of a specified type . IEnumerable < AnonymousType > collections returned by LINQ queries
are n - tuples, where n is the number of the projection ’ s members. A quadruple results from a
four - member projection. EDM calls the tuples AssociationSet s and names them from the
underlying foreign - key constraint name, typically FK_ Source Target for SQL Server where
Source is the EntityType name of the End that represents the 1 side of a 1:many relation and
Target is the many End .
Roles are the function that the entity performs in the relationship, such as Husband and Wife for
Person entities in a Marriage relationship. An EDM Association represents each associated
EntityType as an End that has a Role attribute.
Mappings specify the potential number of entities that can participate in the relationship, which
more commonly is called cardinality. Cardinality can be 1: n (one - to - many, such as order:
lineitems), m :1 (many - to - one, such as customer:orders) and m : n (many - to - many, such as
products:suppliers.) EDM substitutes a Multiplicity attribute for each End of an
Association : 1 represents that a single EntityType is required, 0...1 indicates that a single
EntityType is optional, and * represents many.
Attributes are functions that that map from an entity set to a value set ; for example an OrderDate
attribute maps to a Date/Time value set, which (for SQL Server) ranges from 1753 - 01 -
01T00:00:00 to 9999 - 12 - 31:23:59:59. EDM calls an attribute a Property , instead of a field or
column.

Comprehending Entity Framework Architecture and Components

The Entity Framework implements and exploits the Entity Data Model with the following four major
components:
Mapping files and EDM Designer . Three XML files manage mapping for the transition from
the physical (relational or store) schema to the conceptual (business - object - oriented) schema.
Defining mapping in XML files minimizes — but doesn ’ t eliminate in v1 — persistence - related
attributes in business - object classes and prevents the need for reflection at runtime. The
graphical EDM Designer autogenerates a single ModelName .edmx file and the top - level
ObjectContext and EntityName business - object classes, whose use is optional, in ModelName
.Designer.cs or ModelName .Designer.vb . Building the project creates the three mapping
XML files, ModelName .ssdl , ModelName.msl , and ModelName .csdl and stores them in the
assembly as resources.
EntityClient , Entity SQL, and Client Views . EntityClient is anADO.NET data provider
that processes entity queries written in an entity - enabled SQL dialect called Entity SQL to
generate Client Views with a DbDataReader . EntityClient emulates SqlClient ’ s
properties with EntityConnection , EntityCommand , EntityDataReader , and other
Entity... properties and objects. The syntax of Entity SQL queries is identical for all database
brands that have a storage - specific ADO.NET data provider, such as the current SqlClient
version. EntityClient hands off its Canonical Query Tree (CQT, an expression tree, sometimes
called a Canonical Command Tree or CCT) to the storage - specific data provider, which
translates the CQT to the RDBMS ’ s SQL dialect.
Object Services . Object Services is a layer over the EntityClient that provides an
ObjectQuery instance to execute Entity SQL statements that return strongly typed business
object instances instead of high - performance Client Views. The ModelName .Designer.cs or
ModelName .Designer.vb file defines the business classes at design time. Use of the Object
Services layer is optional.
LINQ to Entities Provider . LINQ to Entities is a domain - specific LINQ implementation that
uses an IQueryable < T > expression to generate an expression tree, which the EntityClient
translates to a CQT and passes to the storage - specific data provider. The storage - specific
provider returns a DbDataReader , which EntityClient coverts to a IEnumerable < T >
sequence for the data access or presentation layer. In this respect, LINQ to Entities parallels
LINQ to SQL ’ s query pipeline that uses expression trees to output T - SQL.
The first two of the preceding components are common to the Entity Data Model in its role as a
foundation for future members of the nascent Entity Data Platform.

Thursday, May 5, 2011

LINQ to REST (Cloud Programming)


LINQ to REST
Roy Fielding, one of the authors of the Internet Engineering Task Force ’ s HTTP specification (RFC 2216),
introduced the term Representational State Transfer and its abbreviation REST in his 2000 doctoral
dissertation, “ Architectural Styles and the Design of Network - based Software Architectures. ”
Wikipedia ’ s definition of REST begins as follows:
REST strictly refers to a collection of network architecture principles that outline
how resources are defined and addressed. The term is often used in a looser sense to
describe any simple interface that transmits domain - specific data over HTTP
without an additional messaging layer such as SOAP or session tracking via HTTP
cookies. . . . Systems that follow Fielding ’ s REST principles are often referred to as
RESTful .
LINQ to REST is a component of ADO.NET Data Services (ANDS), which began life in early 2007 as a
Microsoft Live Labs incubator project named Astoria . Astoria used the term REST in the “ looser sense ” to
describe an API that defines a method for delivering relational data over the Web with a simpler API
than SOAP. At that time, many Web - centric organizations were creating “ open, ” RESTful APIs for
accessing a variety of data types, including data structures, that support HTTP as the wire protocol and
integrate easily with AJAX and other technologies, such as Adobe Flash and Microsoft Silverlight, to
deliver lightweight client programs that run in popular browsers. The common term for these programs,
which developers often use to create Web mashup s, is Rich Internet Application (RIA).
The incubation team chose the codename Astoria because the project originally was subtitled “ Data
Service in the Cloud ” and Astoria is the cloudiest city in the United States.
Mashup originated as a pop - music term that means creating a new tune by mixing multiple existing
tunes. In the Internet context, mashup means combing data from multiple sources into a Web page or
application. An early example was associating Web - based maps with real - estate classified
advertisements on Craigslist and similar sites.
Microsoft insists that RIA is the abbreviation for Rich Interactive Applications.
REST transfers state between resources (a source of specific information) and clients. Resources,
such as data tables, rows, and columns, must be uniquely addressable. RESTful resources must expose
to clients a uniform interface that has a set of predefined operations and content types; these
requirements are similar to those of a SOAP service ’ s contract. ANDS meets these criteria. The client/
server protocol for transferring state must be stateless, cacheable and layered. HTTP satisfies these
requirements, enables state to pass through most firewalls, and provides predefined methods for client
authentication.
Google Base, an attribute - centric (non - relational) database, was an early RESTful, publicly accessible
Web data source; Amazon announced in December 2007 the beta version of SimpleDB, another cloud -
based non - relational RESTful data store that stores data in key - value pairs. The initial Astoria
implementation, which featured a publicly accessible Web implementation of the Northwind sample
database and a few other data sources, used the Entity Framework (EF) as its preferred back - end
object/relational data store. ANDS with Entity Framework as object data source is one of the topics of
Chapter 15 . Figure 8 - 3 is a data flow diagram for ADO.NET Data Services using EF, LINQ to SQL, or
other LINQ - compliant data sources.
Astoria implements the IUpdatable < T > interface for EF so EF data sources are updatable. LINQ to
SQL and other data sources that don ’ t implement IUpdatable < T > are read - only.

Sunday, April 24, 2011

Parallel LINQ

Parallel LINQ
Adding more cores to PC microprocessors has become the preferred approach to increasing CPU
performance while minimizing incremental power consumption and thermal radiation. Prior to the
advent of multi - core processors, increasing clock speed was the only method of improving performance
of a specific CPU design. Decreasing the lithographic line width mitigates the increase in thermal
radiation as clock speed increases at the expense of building new CPU fabrication (fab) lines and plants.
Intel ’ s new 45 - nanometer (nm) process (code - named Penryn) supports up to 800 million transistors on a
single chip. Intel ’ s planning clock speeds of 3 GHz and greater for dual - core Penryn chips used in
desktop PC desktops and servers, but going below 45 nm and above 3 GHz will be extremely costly
compared with putting two Penryn chips in a package to create quad - core packages that share a 12 - MB
or larger Level 2 cache.
Operating systems and server applications, such as SQL Server 2000+, Windows Server 2003+, and
others, are designed to take advantage of multiple CPUs, whether in individual packages or on a
single die. Windows Vista accommodates quad - core CPUs but most client - side applications, written by
in - house developers or independent software vendors, aren ’ t designed to take full advantage of even
dual - core CPUs. Sophisticated multi - threaded applications aren ’ t easy to write or simple to test
thoroughly.
Parallel LINQ (PLINQ) is a component of the Microsoft Parallel Extensions to .NET Framework 3.5,
which in turn is part of the Microsoft Parallel Computing Initiative (PCI). The object of the PCI is to take
better advantage of multiple - core processors by taking the pain out of parallel (concurrent) processing of
LINQ to Objects, LINQ to XML, and LINQ to DataSet queries. PLINQ is less applicable to LINQ to SQL
and LINQ to Entities queries because queries are processed primarily by database servers. However,
PLINQ can speed processing heterogeneous queries with sequences from relational domains. PLINQ
parallelizes queries by relatively simple modifications to LINQ expression (comprehension) syntax and
only slightly more cumbersome modifications of method call syntax. LINQ ’ s declarative programming
methodology, which describes the result that ’ s wanted instead of how to accomplish the result, gives
PLINQ the flexibility to accomplish its objectives without resorting to complex programming structures.
The starting point for additional information on PLINQ and the Parallel Extensions is the Microsoft ’ s
Parallel Computing Center ( http://msdn.microsoft.com/en - us/concurrency/default
.aspx ). The Parallel Extensions also contain the Task Parallel Library (TPL) and a hidden
implementation of the Coordination Data Structures (CDS), which are beyond the scope of this
chapter ’ s declarative LINQ programming. The June 2008 CTP includes CDS documentation.
Programming with PLINQ
Using PLINQ with a project requires the following three operations:
1. Download and run the Microsoft Parallel Extensions to .NET Framework 3.5, June 2008 (or later)
Community Technology Preview. (Search for “ Microsoft Parallel Extensions ” with the quotation
marks.)
2. Add a reference to System.Threading.dll to add the System.Threading namespace to your
project.
3. Add using System.Threading; or Imports System.Threading to your classes that contain
LINQ queries.
4. Replace the Standard Query Operator ’ s IEnumerable < T > type for sequences with
System.Linq.ParallelEnumerable < T > by calling the System.Linq.ParallelEnumerable
.AsParallel < T > extension method. AsParallel and AsParallel < T > appear in IntelliSense ’ s
AutoComplete list between AsEnumerable < T > and AsQuerable .
The System.Threading namespace extends System.Linq with the following two namespaces to
implement PLINQ:
System.Linq extends .NET 3.5 ’ s System.Linq namespace with IParallelEnumerable < T >
and IParallelOrderedEnumerable < T > interfaces and ParallelEnmerable ,
ParallelQuery and ParallelQueryOptions classes. ParallelEnumerable provides the
SQO parallel processing extension methods. ParallelQuery provides the AsParallel() ,
AsParallel < T > () , and AsSequential < T > () methods. ParallelQueryOptions supports the
PreserveOrdering option to force parallel processing of the output sequence to following
the input sequence and the integer DegreeOfParallelism argument that specifies the
maximum number of threads. System.Linq also includes a number of related internal
sealed / Friend NotInheritable classes.
System.Linq.Parallel adds the Parallel namespace with an Enumable class of extension
methods and a large number of internal sealed / Friend NotInheritable helper classes.
Add the \Program Files\Microsoft Parallel Extensions Jun08 CTP\System
.Threading.dll file to Lutz Roeder ’ s Reflector application if you want to explore the classes in
detail. Note that Jun08 might have changed to a later date.
The IParallelEnumerable < T > interface derives from IEnumerable < T > and adds only the overhead
needed to enable binding to PLINQ ’ s ParallelEnumerable query provider. Here ’ s the basic syntax for
LINQ expression and method call syntax with the PreserveOrdering option and four threads maximum
specified:
C# 3.0
// Sequential (standard) query - method call syntax (C#)
var query = dataSource
[.Where(a = > a. Prop1Name == someValue )
.Orderby(a = > a. Prop2Name )
.Select(a)];
foreach (var a in query)
{
// Do something with a
}
// Parallel (pipelined) query - method call syntax
var query = dataSource
.AsParallel([QueryOptions.PreserveOrdering[, 4]])
[.Where(a = > a. Prop1Name == someValue )
.Orderby(a = > a. Prop2Name )
.Select(a)];
foreach (var a in query)
{
// Do something with a
}
// Parallel (pipelined) query - query expression syntax
var query = for a in dataSource.AsParallel([QueryOptions.PreserveOrdering[, 4]])
[where a. Prop1Name == someValue
orderby a. Prop2Name ]
select a;
foreach (var a in query)
{
// Do something with a
}
Processing Queries
PLINQ offers the following three query processing options:
Pipelined processing uses n - 1 threads to run the parallel query and one thread to enumerate
the query, where n is the number of processor cores in the machine. This method ensures
that the foreach / For Each...Next loop can process elements as they exit parallel processing,
which minimizes memory consumption for temporary storage of elements. When the
enumerator thread invokes MoveNext() method, the processing thread(s) deliver a result as
quickly as possible; the enumerator thread blocks until a result is available. Pipelined processing
is the default unless you invoke the ToArray() , ToDictionary() , ToList() , or ToLookup()
method or include the OrderBy() or OrderByDescending() SQO in your query. Pipelined
processing uses the basic query syntax shown in the preceding examples.
Stop - and - go processing starts with a call to MoveNext() . The enumerator thread then enlists
threads from the remaining cores to complete parallel query processing. This method stores
elements in memory; the first thread enumerates the output and the subsequent MoveNext()
invocation when parallel query processing completes returns the entire output. Additional
MoveNext() invocations return the same data from the buffer. You select stop - and - go
processing by invoking PLINQ ’ s GetEnumerator( pipelined ) overload with pipelined =
false . Stop - and - go processing is used for To...() methods and queries sorted with
OrderBy[Descending]() because these operators force all - at - once processing. Stop - and - go
processing uses the iteration syntax shown in the following example.
Inverted enumeration requires supplying a lambda function to run in parallel one time for each
element. Inverted enumeration doesn ’ t incur the overhead of merging the output from multiple
threads. Inverted enumeration requires substituting the ForAll API for foreach / For Each...
Next and the lambdas cannot share state. The later “ Ray Tracing ” section has an example of
inverted enumeration with the ForAll API.
C# 3.0
// Enumeration with stop-and-go processing (C#)
using (var q = query.GetEnumerator(false))
{
while (q.MoveNext())
{
// the first invocation starts query processing
// then enumerate the results with
operationOn(q.Current);
}
}

Friday, April 15, 2011

دجت اوقات شرعی شیعه که برای ویندوز ویستا و سون

دجت اوقات شرعی شیعه  که برای ویندوز ویستا و سون قابل استفاده هست
برای استفاده از این دجت میبایست به اینترنت متصل باشید
این برنامه رایگان و قابل انتشار می باشد
تقدیم به همه ایرانیان

لینک دانلود


برای دوستان نیز ارسال فرمایید