EF: Losing Relationship Includes on Detach

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);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top