实体框架6 - 来自多个表的配置映射

时间:2014-11-05 14:49:54

标签: entity-framework entity

我有两张表,如下所示:

http://s30.postimg.org/i3u7pmpz5/baza.png

我创建的模型如下所示:

public class DomainUser : User
{
    public Guid Guid { get; set; }
    public string Sid { get; set; }
    public string Title { get; set; }
    public string Company { get; set; }
    public string Department { get; set; }
    public string Office { get; set; }
    public virtual DomainPhone Phone { get; set; }
    public virtual DomainEmail Email { get; set; }
    public string Created { get; set; }
    public string CreatedBy { get; set; }
    public string Modified { get; set; }
    public string ModifiedBy { get; set; }
}

public abstract class User
{
    public int Id { get; set; }
    public string Login { get; set; }
    public string Name { get; set; }
    public string MiddleName { get; set; }
    public string Surname { get; set; }
    public bool IsActive { get; set; }
}

我想用表DomainUser和User的数据创建DomainUser对象。 以下是我们要通过EF生成的示例查询:

 select  [Extent1].[Id] as [Id], 
        [Extent1].[Login] as [Login], 
        [Extent2].[Guid] as [Guid], 
        [Extent2].[Sid] as [Sid], 
        [Extent2].[Title] as [Title], 
        [Extent2].[Company] as [Company], 
        [Extent2].[Department] as [Department], 
        [Extent2].[Office] as [Office] 
from    [dbo].[User] as [Extent1] inner join [dbo].[DomainUser] as [Extent2] on [Extent1].[Id] = [Extent2].[Id]

我怎么能做到这一点?

0 个答案:

没有答案