0

我有两个要使用 EntityFramework 查询的表,使用了一个主表,这是用于存储辅助数据的第二个表,我希望我可以进行左连接,但我做不到,这里是元素:

public class TableA
{
    public int Id {get; set;}
    public string Value {get;} set
}

public class OptionalDataTableB
{
    public int OptionalDataTableBId {get; set;}
    public string OtherValue {get; set;}
}

这里的映射类

public class TableAMap: EntityTypeConfiguration<TableA>
{
    public TableAMap ()
    {
        this.HasKey (e => e.Id);
        this.Property (e => e.Id)
                  . IsRequired ()
             .HasDatabaseGeneratedOption(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity);

    }
}

public class OptionalDataTableBMap: EntityTypeConfiguration<OptionalDataTableB>
{
    public OptionalDataTableB ()
    {
        this.HasKey (e => e.OptionalDataTableBId);
        this.Property (e => e.OptionalDataTableBId)
           . IsRequired ()
    }
}

我想与 DbContext 建立关系

public class MyDbContext: DbContext
{
    protected override void OnModelCreating (DbModelBuilder ModelBuilder)
    {
        modelBuilder.Configurations.Add (new Mapping.TableAMap());
        modelBuilder.Configurations.Add (new Mapping.OptionalDataTableBMap());
    }
}

如何配置映射才能产生这种请求?:

select * 
from TableA 
    left join OptionalDataTableB On TableA.Id = OptionalDataTableB.OptionalDataTableBId
4

1 回答 1

0

MSDN 中的以下内容应该回答您的问题:http: //msdn.microsoft.com/en-us/data/hh134698.aspx

于 2012-11-21T21:53:09.487 回答