If I use entity framework with linq to sql to query it and I have an object Person but I only need two properties of that object, what's in memory will be load, the entire object ?
Example :
I got the entity Person with properties : Name, Age, Address, Country, Language ...
I only need to use the property Name and Age. So I got no need to load the address, country and other property ... what will be in memory and what type of query will be ask to SQL ?
If my Linq query is :
public IQueryable<Person> FindAllPersons()
{
return from person in db.Persons
select person;
}
And later in code I only call the Name and Age property of each Person in the list.
As an alternative, you can set Delay Loaded to true for all columns you don't want to be loaded instantly.
You can query for only the fields you need.
Like so,
public IQueryable<Person> FindAllPersons()
{
return from person in db.Persons
select new Person(){Name = person.Name, Age = person.Age};
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With