dimanche 28 juin 2015

How should I disable Entity Framework table refrence(foreign) list from each other objects?

I'm using Sqlite database and System.Data.SQLite 1.0.92 There is 2 table here:


Table Person:

PersonId

PersonName


Table Student:

StudentId

PersonId(reference table Person FK)

StudentNo


Now every time I get the Persons Collection in EF5:

using (var ctx = new myEntities)
{
  AllPersons = ctx.Persons.ToList();
}

There is also has AllPersons.student collection will include in the result;

But I don't need it. Of course that's just an example, There is a lot of big table has so many references, it always has performance problems here because of that.

So I'm trying to do not let it in my result. So I change it:

using (var ctx = new myEntities)
{
      ctx.Configuration.ProxyCreationEnabled = false;
      ctx.Configuration.LazyLoadingEnabled = false;
      AllPersons= ctx.Persons.ToList();
}

Now fine, because AllPersons.student collection will always be null

But now I found: If I get Person and Student together:

using (var ctx = new myEntities)
{
    ctx.Configuration.ProxyCreationEnabled = false;
    ctx.Configuration.LazyLoadingEnabled = false;
    AllPersons= ctx.Persons.ToList();
    AllStudents = ctx.Student.ToList();
}

Now the reference still include in.

So Is there anyway to don't let the reference include in any time in this situation? Thank you.

Aucun commentaire:

Enregistrer un commentaire