Home > Net >  Using c # to the Entity Framework of lazy loading of a little doubt, seek to reassure
Using c # to the Entity Framework of lazy loading of a little doubt, seek to reassure

Time:09-30

Use EF6 query the database data, the results of a query is not the same as expected, the database structure is simple, data types are all int,

Query twice, using different keyword query, the query results is the same, the second query the first covers the results of the query, the query code as shown in figure,

But if you use the picture comment out code query, coverage, will happen at the time of debugging is also found that, with the current code debugging, found out the results of the query enumeration is normal for the first time, but the second query again after the result of the enumeration result is found for the first time is wrong, this should be related to EF of lazy loading, but I understand lazy loading should at least give recorded the query expression, how can regenerate the expression in the query time? So a bit worried about the code before a similar problem,

CodePudding user response:

Where st. id==1 | | st. id==2 so sweet

CodePudding user response:

Could it be id value changed reason?

CodePudding user response:

reference 1st floor libolei response:
where st. id==1 | | st. id==2 aren't so sweet

I am need to equal to two id out respectively, and then assigned to the two objects, cannot be together,

CodePudding user response:

The
refer to hand on the keyboard to knock on the second floor is very light response:
id values are changed?

Sure because of the id value has changed, but this does not accord with my expectations, why such a design?

CodePudding user response:

Query out then points in the general case the higher the efficiency of the less number of database access can do, don't trouble to program database

CodePudding user response:

reference 5 floor libolei reply:
query out then points in the general case the higher the efficiency of the less number of database access can do, don't trouble to program database

Now I concern is not found out after the points, I this program requirements for efficiency is not high, just found out that I thought Mr EF lazy loading is a SQL statement, and then need the results to the query, query for the first time "select * from testyc where id=1", then the second query "select * from testyc where id=2", but it seems not like that,
  •  Tags:  
  • C #
  • Related