Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Entity framework EF多对多连接-禁用延迟加载_Entity Framework_Linq To Entities_Entity Framework 5_Code First_Entity Relationship - Fatal编程技术网

Entity framework EF多对多连接-禁用延迟加载

Entity framework EF多对多连接-禁用延迟加载,entity-framework,linq-to-entities,entity-framework-5,code-first,entity-relationship,Entity Framework,Linq To Entities,Entity Framework 5,Code First,Entity Relationship,以下是我的设想: public class Contact { public Guid ContactId { get; set; } ........ public Guid WorkspaceId { get; set; } public Workspace Workspace { get; set; } } public class Workspace { public Guid WorkspaceId { get; set; } ...

以下是我的设想:

public class Contact 
{
    public Guid ContactId { get; set; }
    ........
    public Guid WorkspaceId { get; set; }
    public Workspace Workspace { get; set; }
}

public class Workspace
{
    public Guid WorkspaceId { get; set; }
    ........
    public ICollection<Contact> ReferencedContacts { get; set; }
    public ICollection<Contact> OwnedContacts { get; set; }
}
我试图做的是使用查询方法获取特定工作区的所有引用联系人。查询的SQL版本如下所示:

从dbo.Contacts c中选择* 内部联接dbo.WorkspaceReferencedContacts wc ON wc.ContactId=c.ContactId 其中wc.WorkspaceId='57F685C0-428C-44C3-8708-F30B5AF34CAE'

我用了很多方法,但都没有成功请注意,延迟加载被禁用(没有必要讨论为什么…

…获取特定工作区的所有引用联系人

我认为:

var contacts = context.Workspaces
    .Where(w => w.WorkspaceId == "57F685C0-428C-44C3-8708-F30B5AF34CAE")
    .Select(w => w.ReferencedContacts)
    .SingleOrDefault();
var contacts = context.Workspaces
    .Where(w => w.WorkspaceId == "57F685C0-428C-44C3-8708-F30B5AF34CAE")
    .Select(w => w.ReferencedContacts)
    .SingleOrDefault();