Loading behavior of EF v1?

another Entity Framework question (ADO.NET) from me. I use EF1 (there is no choice) and there is a MySQL database as the database.

A simple question: I can not find a satisfactory answer for:

What exactly do I need to do to download? IE., When I have an entity and you want to list its children, let's say that I have Entity "Group" and it has a child "User" and I want to make "from n to g.Users, where n .UserID = 4 select n ", first I need to call g.Users.Load ();

This is a little annoying because when I make a request against an unloaded collection, I would expect EF to load it automatically - will AT LEAST throw an exception, and not just return 0 results?

Another case when I have to take care of the download: I have a request:

from n in Users where n.Group.Name == "bla" select n

For some reason, it fails by nulling a pointer to n.Group, although n.GroupID (the key for the group) is set correctly. In addition, when I did Server.Groups.Load () before (groups are children of one server), it works.

Is there any specific policy on when to call Load () which collection?

Thanks again Michael

+3
source share
3 answers

. , -, , , , . Include() ( Rup ) , , , Include() . ( Rup ), , , .

, , , . , . , , , , , . , , , , , .

+2

ObjectQuery.Include,

var g = from g in MyDb.Groups.Include("Users") where g.Id = 123 select g;
from n in g.Users where n.UserID = 4 select n

from n in Users.Include("Group") where n.Group.Name == "bla" select n

Load() , ,

if (g.CanLoadReferences() && !g.Users.IsLoaded)
{
    g.Users.Load();
}

( - LINQ EF4 )

+1

This works when we start the MS SQL server, it may be a limitation in the MySQL adapter.

Are you using the latest version 6.2.3? See: http://www.mysql.com/downloads/connector/net

0
source

Source: https://habr.com/ru/post/1761274/


All Articles