Sunday, October 31, 2010

yield keyword : Lazy and Eager Evaluation

The most important element of the Where extension method code is the yield return item
instruction that the iterator executes if item meets the Where criterion ( predicate expression). C# 2.0
introduced the yield contextual keyword but few developers used it. The compiler recognizes yield as
a keyword only if it ’ s followed by return or break . The yield return item instruction in an iterator
block enables an enumerable class to be implemented in terms of another enumerable class; that is,
chained.

Lazy and Eager Evaluation
The yield return item instruction enables lazy evaluation , which is another feature critical to LINQ.
Lazy evaluation means that a LINQ code doesn ’ t touch the query ’ s data source until the code executes
the iterator ’ s first yield return item instruction. Lazy evaluation makes execution of chained
extension methods very efficient by eliminating storage of intermediate results. Lazy evaluation is the
key to object/relational mapping (O/RM) tools ’ lazy loading of objects related to your main object by
associations. Lazy loading means that the O/RM tool doesn ’ t load related objects until the application
needs to access their property values.
Eager evaluation means that the query is self - executing. For example, chaining an aggregate function to
the end of a query causes immediate evaluation. The following snippets demonstrate eager evaluation
with the Count() expression method in query expression and method call syntax:
C# 3.0
var noStockCount1 = (from p in productList
where p.UnitsInStock == 0
select p).Count();
result = “\r\nCount of out-of-stock items = “ + noStockCount1.ToString();
var noStockCount2 = productList
.Where(p = > p.UnitsInStock == 0)
.Count();
result = “\r\nCount of out-of-stock items = “ + noStockCount2.ToString();

Sunday, October 24, 2010

The ADO . NET Entity Framework and Entity Data Model

The ADO . NET Entity Framework and
Entity Data Model
Microsoft ’ s ADO.NET team began designing the Entity Framework (EF) and Entity Data Model (EDM)
near the date in 2003 when the C# 3.0 design group decided to develop a LINQ to SQL extension as a
“ stand - in ” for the abandoned ObjectSpaces O/RM tool project. The two projects progressed in parallel,
apparently with little or no communication between the two groups. In early 2006, the ADO.NET team
gained ownership of the LINQ to SQL and LINQ to DataSet implementations and added LINQ to
Entities as an optional method for executing queries over the EDM. The ADO.NET group presented
several sessions at Tech * Ed 2006 and published a series of whitepapers about EF and EDM in June 2006.
The “ Next - Generation Data Access: Making the Conceptual Level Real ” technical article by Jos é Blakeley,
David Campbell, Jim Gray, S. Muralidhar, and Anil Nori, proposed to extend the EDM from basic CRUD
operations to reporting and analysis services (business information) and data replication.
You can read the preceding technical paper at http://msdn2.microsoft.com/en - us/
architecture/aa730866(vs.80).aspx and its companions, “ The ADO.NET Entity Framework
Overview ” at http://msdn2.microsoft.com/en - us/architecture/aa697427(VS.80)
.aspx and “ ADO.NET Tech Preview: Entity Data Model ” at http://msdn2.microsoft.com/
en - us/architecture/aa697428(VS.80).aspx .
EF is a much more than an O/RM tool. EF provides a complete set of data services including:
Query services
ClientView services
Persistence services
Object services
EF is the first concrete implementation of the EDM and enables developers to abstract the physical
storage schema of relational databases to a conceptual schema (also called a conceptual layer or conceptual
model) that conforms to the entity - relationship (E - R) data model. Dr. Peter Chen proposed the E - R data
model in a 1976 paper, “ The Entity - Relationship Model — Toward a Unified View of Data, ” which you
can read at http://bit.csc.lsu.edu/
˜
chen/pdf/erd.pdf . E - R became a mainstay of data
modeling for relational databases and the foundation for many computer - aided software engineering
(CASE) tools.
The E - R model is independent of the underlying relational database management system (RDBMs) or
data retrieval and update language, syntax or dialect, but an SQL flavor is assumed. Microsoft says that
EF “ is an execution runtime for the for the E - R model ” that ’ s RDBMS - agnostic. As you would expect,
SQL Server 200x and SQL Server Compact Edition (SSCE) have SqlClient - derived EntityClient
data providers for EF v1.0. When this book was written, IBM DB2, IS, and U2, as well as Oracle,
MySQL, and SQLite supported EF with custom EntityClient data providers for .NET. The
EntityClient object provides EntityConnection , EntityCommand , EntityParameter and
EntityDataReader objects. EntityClient has its own query language, Entity SQL (eSQL), which is
related to SQL but has entity - specific extensions. eSQL v1 has no data management language (DML)
constructs for INSERT , UPDATE or DELETE operations. Microsoft promises to implement entity -
compatible DML in a future version.
An EDM EntityType specifies an object in the application domain that is represented by data. An
EntityObject is an instance of an EntityType , has one or more Properties , and is uniquely
identified by an EntityKey . Properties can be of SimpleType , ComplexType or RowType . An
EntitySet contains multiple EntityObject instances, an EntityContainer holds multiple
EntitySet s, and corresponds to the database (such as Northwind) at the physical data store layer and
schema (such as dbo) at the conceptual level. A RelationshipType defines the relationship of two or
more EntityType s as an Association , which is a peer - to - peer relationship or Containment , that
specifies a parent - child relationship. The top - level EDM object is a Schema , which represents the entire
database.
Following are some of the most important benefits of implementing EDM in data - intensive .NET
projects:
Generates a data access layer that isolates the data domain from the application domain
Handles relational database vendor or schema changes without the need to alter C# or VB
source code and recompile the project
Enables the business logic layer to work with real - world business entities, such as customers,
orders, employees, and products, rather than rows and tables of relational databases
Supports complex properties, such as PhysicalAddress, which might include Street1, Street2,
City, State, ZipCode, Country and Coordinates, and PostalAddress, which might include only
PostOfficeBox, City, State, PostalCode and Country.
Models object - oriented concepts such as inheritance and hierarchical (nested) or polymorphic
resultsets, which don ’ t fit the relational model
Exposes relationship navigation properties to eliminate the need for complex joins between
related tables
Provides an advanced, graphical EDM Designer to simplify inheritance and hierarchy models
and enable incremental changes to mapping files
Maps the conceptual layer ’ s entity model to an object model in the Object Services layer with an
ObjectContext for identity management and change tracking
Enables simple, strongly typed queries with Object Services ’ LINQ to Entities implementation
It ’ s important to bear in mind that EF isn ’ t a traditional O/RM tool and using the Object Services layer
and LINQ to Entities is optional. Mapping to objects occurs at the conceptual layer, so the term object/
entity mapping tool might represent a more accurate description. Where performance is critical, such as
with reporting and analysis services, you can opt to write eSQL queries and return conventional,
untyped DataReaders based on the conceptual layer ’ s schema.

Thursday, October 14, 2010

Pocket PC Windows Mobile English Persian Dictionary Download

Pocket PC Windows Mobile English Persian Dictionary Download

دیکشنری انگلیسی به فارسی ویندوز موبایل پاکت پی سی دانلود

راهنمای نصب :
ابتدا  پکیج دات نت کامپکت فریم ورک سه و نیم را روی گوشی خود نصب کنید
آدرس محل دانلود
سپس فولدر برنامه دیکشنری موج سوم را روی گوشی خود کپی و فایل اجرایی دیکشنری موج سوم را اجرا نمایید

برای اطلاعات بیشتر با
m.s.rezaaei@gmail.com
مکاتبه بفرمایید

نظرات خود را با ما در مورد بهبود و دیباگ سیستم در میان بگذارید
تقدیم به همه ایرانیان


HTC HD2 Diamond Diamond 2 Samsung i Mate HP ...
DOWNLOAD
http://www.4shared.com/file/2eP5dU7A/MojeSevomDic3.html
http://www.sadatrezaei.com/MojeSevomDic2.rar

Wednesday, October 13, 2010

Extension Methods

" Software Engineers never die… They just go Offline ….  "

Extension Methods
Extension methods let you add custom methods to previously defined types, even if those types are
sealed in C# or NotInheritable in VB. For example, the string / String class is sealed and has 45
predefined instance methods, which you access by dot ( . ) syntax, as in strTest.Length() or “ This
is a test ” .Length() . The compiler treats these statements as if they were members of a function
library: Length(strTest) or Length( “ This is a test ” ) .
The Length method throws an exception if the class value is null or Nothing , so a LengthNullable()
method that returns an int? , Integer? , or Nullable(Of Integer) type eliminates the need to check
for null or Nothing before invoking the Length method. Here ’ s the C# 3.0 code for the
LengthNullable method:
C# 3.0
static class ExtensionMethods
{
public static Int32? LengthNullable(this string test)
{
if (test != null)
{
return test.Length;
}
else
{
return null;
}
}
}
Sample code for the C# 3.0 ExtensionMethods class is located in the ExtensionMethods.cs
class file.

According to VS 2008 ’ s online help ’ s “ extension methods [Visual Basic] ” topic, you can apply extension
methods to any of the following types:
Classes (reference types)
Structures (value types)
Interfaces
Delegates
ByRef and ByVal arguments
Generic method parameters
Arrays
C# 3.0 extension methods must be defined by a public static method within a public static or
internal static class. Prefixing the method ’ s first argument with the this keyword (highlighted in
the code) informs the compiler that the function is an extension method. The second argument is the
type to which the method applies, string for this example, and the third is the instance name, test .
Extension methods support full statement completion and IntelliSense features.
A downward - pointing arrow added to the IntelliSense list ’ s method icon identifies extension methods.
Following are a few C# test methods to verify that the new extension method behaves as expected:
C# 3.0
// Import the namespace if method is in another project
using CS3Extensions.ExtensionMethods;
// Extension method tests
string nada = null;
string test = “This is a test”;
int? len0 = nada.LengthNullable();
int? len1 = test.LengthNullable();
int? len2 = “This is a test”.LengthNullable();
You can create VB 9.0 extension methods in modules only, and you must add an Imports System
.Runtime.CompilerServices directive to support the < Extension() > attribute. This attribute is
necessary to instruct the compiler that the function is an extension method. VB functions declared within
modules are static, so the Shared keyword isn ’ t required. The argument ’ s type declaration specifies the
class to which the extension method applies.
VB 9.0
Imports System.Runtime.CompilerServices
Public Module ExtensionMethods
‘ VB extension methods can only be declared within modules
< Extension() > _
Public Function LengthNullable(ByVal Test As String) As Integer?
If Test Is Nothing Then
Return Nothing
Else
Return Test.Length
End If
End Function
End Module
Sample code for the VB 9.0 ExtensionMethods module is located in the ExtensionMethods.vb
module file.
As with the C# version, you must import the VB module ’ s namespace to bring the extension method
within the application ’ s scope, if the module isn ’ t in the same project. The VB test code is quite similar to that for the C# version.

Wednesday, October 6, 2010

C# and VB Extensions to Support LINQ

C# and VB Extensions to Support LINQ
LINQ is responsible for most new language extensions in VS 2008. Here ’ s a list of the LINQ - related
extensions to C# 3.0 and VB 9.0 with brief descriptions of their purpose:
Implicitly typed local variables infer the type of local variables from the expressions used to
initialize them.
Object initializers simplify the construction and initialization of objects of arbitrary types.
Array initializers extend object initializers to elements of arrays of arbitrary types. VB 9.0
doesn ’ t support array initializers.
Collection initializers (also called implicitly typed array initializers) extend the array initializer
style to infer the element type of the collection from the initializer. VB 9.0 doesn ’ t support
collection initializers.
Anonymous types enable creating tuple types with object initializers whose CLR type is
inferred by the compiler. C# anonymous types are immutable, but some VB anonymous types
are mutable.
Extension methods enable extending existing and constructed types with new methods.
Lambda expressions enable C# 2.0 ’ s anonymous methods to deliver better type inference and
allow conversions to expression trees and delegate types. VB 9.0 supports Lambda expressions
but doesn ’ t expose anonymous methods to programmers.
Standard Query Operators (SQOs. Also called Standard Sequence Operators ) filter, transform,
join, group, and aggregate collections of CLR types.
Query expressions group SQOs into a high - level query language that is similar to SQL and
related to XQuery.
Expression trees permit lambda expressions to be represented as data (expression trees) instead
of as code (delegates).
IQueryable < T > and IOrderedQueryable < T > interfaces, in conjunction with expression trees,
facilitate third - party LINQ implementations for other data domains and enable the compiling
of queries for improved performance. IQueryable < T > and IOrderedQueryable < T > types
enable composable queries by passing them as the data source of one or more additional
LINQ queries.LINQ also relies on these language features of C# 2.0 and VB 8.0:
Generic types let you specify the precise data type that a method, class, structure, or interface
acts upon. The primary benefits of generics are type safety and increased code reusability.
Anonymous methods (also called anonymous delegates) let you define a nameless method
that ’ s called by a delegate and access variables that would normally be out of scope. VB doesn ’ t
support anonymous methods directly.
Iterators , specifically the generic, type - safe IEnumerable < T > interface, in the System
.Collections.Generic namespace, which supports iterating over a generic collection in a
foreach or For Each ... Next loop.
Programs that don ’ t execute LINQ queries can take advantage of most new VS 2008 features. LINQ will
introduce the more abstract functional constructs, such as lambda expressions and expression trees, to
most .NET developers.

Tuesday, October 5, 2010

Lambda Expressions

 
Lambda Expressions
A lambda expression is a convenient means to assign an expression or block of code (an anonymous
method) to a variable (a delegate). A lambda expression accomplishes this with an absolute minimum
amount of typing. Although VB 9.0 doesn ’ t offer anonymous methods, it does support lambda
expressions, which members of Microsoft ’ s VB team also call inline methods . Without support for lambda
methods VB developers couldn ’ t take advantage of LINQ.
Here ’ s the basic syntax for lambda expressions:
argument-list = > expression-or-statement-block // C# 3.0
Function(argument-list) expression ‘ VB 9.0
Lambda expressions extend anonymous methods with the following capabilities:
Parameter type inference, which eliminates the need to specify parameter types
Conversion to expression trees, which treat code as data
Pass as method arguments, implementing argument type inference and method overload
resolution
Substitution of C# statement blocks for expressions, where necessary
VB 9.0 lambda expressions don ’ t support statement blocks.
Lambda expressions implement the method call syntax form of LINQ ’ s Standard Query Operators
(SQO), which are the subject of the later “ Standard Query Operators ” section and Chapter 3 and
Chapter 4 .
C# 3.0 Lambda Expressions
Moving from the anonymous method to lambda expression syntax is a stepwise process. Here are the
steps using the sample delegate(LineItem i) { return i.UnitPrice > = 25M; } anonymous
method from the last (C#) example of the earlier “ Anonymous Methods and Generic Predicates ” section:
1. Delete the delegate keyword, leaving (LineItem i) { return i.UnitPrice > = 25M; } .
2. Replace the French braces with the lambda operator ( “ fat arrow ” ), leaving (LineItem i) = >
return i.UnitPrice > = 25M; .
3. Remove the return keyword and delete the semicolon because i.UnitPrice > = 25M has
become an expression, leaving (LineItem i) = > i.UnitPrice > = 25M .
4. The compiler can infer the type, so remove LineItem and the parentheses, which leaves i = >
i.UnitPrice > = 25M , an operable lambda expression to supply the predicate.
The lengthy predicates test code that uses an anonymous function becomes:
C# 3.0
// Predicates test (lambda function)
var anon = LineItemsList.Find( i = > i.UnitPrice > = 25M );
The Find() method of the preceding example is called a singleton method because it returns a single
LineItem type, not an IEnumerable < T > type.
Most folks pronounce the lambda operator ( = > ) “ goes to ” but some prefer “ such that ” or “ begets. ”
Generic List < T > types support IEnumerable < T > and foreach / ForEach iteration. The following code,
which resembles some of the simple LINQ queries you saw in Chapter 1 , adds two LineItemsList
rows and a count of LineItem s with UnitPrice values > = $20.00.
C# 3.0
// Predicates test (lambda function, multiple values)
result = “\r\nPredicate(Of T) Test (Lambda Function, Multiple Items) \r\n”;
var mult = LineItemsList.FindAll(i = > i.UnitPrice > = 20M);
foreach (var i in mult)
result += i.OrderID.ToString() + “\t” + i.ProductID.ToString() + “\t\t” +
i.UnitPrice.ToString() + “\r\n”;
txtResult.Text += result;
The FindAll() method returns an IEnumberable < T > type to enable iteration with the foreach
operator. The FindAll() method isn ’ t invoked against the LineItemsList collection until execution
reaches the foreach operator, which executes yield return.
Another capability of lambda expressions is composability by chaining extension methods. Here ’ s a
simple example that returns the number of items with a UnitPrice value > = $20 :
C# 3.0
var quan = LineItemsList.FindAll(i = > i.UnitPrice > = 20M).Count;
txtResult.Text += quan.ToString() + “ Items with Price > = $20.00\r\n”;
You can chain multiple lambda expressions that return IEnumerable < T > types to apply complex
filtering and sorting operations to arrays and List < T > types. The following “ Standard Query
Operators ” section provides examples of chained lambda expressions.

REFERENCE : Wrox.Professional.ADO.NET.3.5.with.LINQ.and.the.Entity.Framework