A
apiringmvp
I am having a weird issue with my EF Includes. I am trying to load a
list of users and Include their records into a detached list (see code
below). before the detach I get 2 Record objects returned after I
detach the User using DetachAll() I lose those Record objects. Is
this by design? Is there a work-around?
Thanks in advanced.
Code
---------------------------
public partial class User
{
public static List<User> GetOnlineUsers()
{
using (LeadLineEntities ctx = new LeadLineEntities())
{
var users = (from u in ctx.Users.Include("Records")
where u.is_online == true
select u).ToList();
ctx.DetachAll(users);
return users;
}
}
}
public static class ObjectContextExtensions
{
public static void DetachAll<T>(this ObjectContext ctx,
List<T> entities)
{
foreach (T entity in entities)
ctx.Detach(entity);
}
}
list of users and Include their records into a detached list (see code
below). before the detach I get 2 Record objects returned after I
detach the User using DetachAll() I lose those Record objects. Is
this by design? Is there a work-around?
Thanks in advanced.
Code
---------------------------
public partial class User
{
public static List<User> GetOnlineUsers()
{
using (LeadLineEntities ctx = new LeadLineEntities())
{
var users = (from u in ctx.Users.Include("Records")
where u.is_online == true
select u).ToList();
ctx.DetachAll(users);
return users;
}
}
}
public static class ObjectContextExtensions
{
public static void DetachAll<T>(this ObjectContext ctx,
List<T> entities)
{
foreach (T entity in entities)
ctx.Detach(entity);
}
}