I have entity User with properties
int Id {get; set;}
which is set as primary key
and property
virtual List<Right> Rights {get; set;}
which is a property holding list of user rights, and is lazy loaded whenever it is needed.
Right is also a property :
public class Right
{
[Key]
public int Id {get; set;}
public RightType RightType { get; set; }
}
public enum RightType : byte
{
Own,
Copy,
Delete
}
In my code I create a user from the database as usual, and later I want to get only the IDs of the rights so I try it this way :
myUser.Rights.Select(x=>x.Id).ToList();
It get me the collection of IDs I want, but the query going to the database is getting all the columns of Rights table which is not nessesary and in other cases it may be very problematic (imagining loading great amnout of data only to get the IDs :/)
the query looks like:
> "SELECT
> [Extent1].[Id] AS [Id],
> [Extent1].[RightType] AS [RightType],
> [Extent1].[User_Id] AS [User_Id]
> FROM [dbo].[Rights] AS [Extent1]
> WHERE ([Extent1].[User_Id] IS NOT NULL) AND ([Extent1].[User_Id] = @EntityKeyValue1)"
Do you have any idea how to load only the IDs ?? any help will be appreciated :)
thank you