Home > Net >  EF beginners, get some data in the table, why do you want to select the first
EF beginners, get some data in the table, why do you want to select the first

Time:10-04

I am a novice, the day before yesterday just started watching EF framework
And found that, in many conditions to get a table of data in time (of course there are many ways), we will use
Using (var context=new... ())
{
Var users=form u in context. The users select u;
If (the name! The users=="") users. The Where (... );
If (tel! The users=="") users. The Where (... );
}


Why, I wonder, I search for example, are
Var users=form u in context. The users select u;

I direct
Var users=context. The users;
Then call
If (the name! The users=="") users. The Where (... );
If (tel! The users=="") users. The Where (... );
Also can get the result, tracking execution of SQL, also does not have a full table query, is generated automatically with the where condition of T - SQL statement

For example, that are var users=form u in context. The users select u?
Personally, I doubt whether need so written before, in 2017 the EF6.0, Microsoft optimized the grammar?
Also please instruct the prawns

CodePudding user response:

Linq query syntax and method syntax

CodePudding user response:

The top of a roof, prawns ha haven't class

CodePudding user response:

For example, that are var users=form u in context. The users select u?
Personally, I doubt whether need so written before, in 2017 the EF6.0, Microsoft optimized the grammar?
- "two grammatical ways, according to the personal code used to that, as to why select this is grammar rules, no matter which way, eventually into Sql statements,

CodePudding user response:

First, the lambda method is used, linq, is the language of words

CodePudding user response:

Why use linq, because many table joint query lambda is hard to write and read,

CodePudding user response:

reference 5 floor daixf_csdn reply:
why use linq, because many table joint query lambda is very difficult to write and read,


In fact, I don't understand is, why
Var users=form u in context. The users select u;

Directly use the
Var users=context. The users; Also the same

CodePudding user response:

Var users=form u in context. The users select u;
And
Var users=context. Users. AsEnumerable ();
Should be the same

CodePudding user response:

For example, that are var users=form u in context. The users select u?
Personally, I doubt whether need so written before, in 2017 the EF6.0, Microsoft optimized the grammar?
- "two grammatical ways, according to the personal code used to that, as to why select this is grammar rules, no matter which way, eventually into Sql statements,

CodePudding user response:

refer to the body of the 6th floor, I am your response:
Quote: refer to the fifth floor daixf_csdn reply:

Why use linq, because many table joint query lambda is very difficult to write and read,


In fact, I don't understand is, why
Var users=form u in context. The users select u;

Directly use the
Var users=context. The users; Also the same as
have what not understand? All roads lead to Rome, in terms of my own habits, single table query I don't like to use linq, use lambda expressions more clear, but the multi-table query, I must use linq, principle is code can be read,

CodePudding user response:

With lambda not more simple

CodePudding user response:


Var users=form u in context. The users select u;
Linq syntax is
Var users=context. The users
Is the lambda syntax,
The same

CodePudding user response:

 using (var context=new... ()) 
{
Var users=form u in context. The users where... The select u;
If (the name! The users=="") from u in the user the where... The select u;
If (tel! The users=="") from u in the user the where... The select u;
}

In fact is actually likely to be like that, rather than the kind of mixed writing you write,

CodePudding user response:

If you make the first paragraph is particularly simple, then the second part, the third part is simple, simple things have what good entanglements style? No complex requirements, in fact you don't see the somebody else is from what was accustomed to write,

CodePudding user response:

refer to 6th floor HtoFire response:
Quote: refer to the fifth floor daixf_csdn reply:

Why use linq, because many table joint query lambda is very difficult to write and read,


In fact, I don't understand is, why
Var users=form u in context. The users select u;

Directly use the
Var users=context. The users; Also the same as


That isn't the point, the theory of programming will be subject to test and not to struggle, the somebody else is focused on based on multiple conditions if statements can be segmented to write the final users query, finally unified to produce the same SQL query to the database, and understand here is by understanding, not by words,

CodePudding user response:

This problem is the historical problem, can be traced back to the. Net 3.0 linq has just come out, is not EF yet at that time, only the linq to SQL

The from u in the context. The Users select u linq of writing is to cater to SQL syntax, are easier to understand as possible for SQL programmers linq code
But also some neither fish nor fowl, such as a select statement must be written in the book, join statements equal rather than=etc.

Personally, using lambda expressions of linq extension methods, set operations are easily understood, more convenient to use,

But the linq query statements have been in use today

CodePudding user response:

Write
 var query=the from x array in the where x.a==1 select x; 
root write
 var query=array. The Where (x=& gt; X.a==1); 
only personal experience of the main difference,

You see example is focused on the if expression and many times (multiple) according to modify the query, finally in linq lazy loading mechanism, in the final send SQL query to the database when you see only one (debug tracking to) compiled SQL query sent to the database, as long as you do this to achieve a goal,

CodePudding user response:

If you must study a few years ago who really distinction between
 var users=form u in context. The users select u; 

With

Var users=context. The users;

Difference, so I think you can study a few years ago
 context. The Users; 
returns the type of data is what?

Assuming that at that time, the expression the return type and the from... The select... Type is the same (compatible), then we can know, at that time people can write directly to the context. The Users, then you "search to the sample, are written in the from... Form may be a "coincidence", not can't write,

CodePudding user response:

Well, if we are concerned with the principle of different writing, will be more simple, and can research and estimate the possibility,

CodePudding user response:

Linq syntax, with lambda syntax, grammar is a completely different set of system, but can be mixed with the native c # syntax seamless use and mixed use,
Because the underlying principle and object are the same, just different syntax,
Your so-called confused, only because no hear both syntax, not dialectical viewnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • LINQ
  • Related