有流畅的api和关系的问题

时间:2012-11-23 12:12:48

标签: c# entity-framework

我在实体框架4.1和关系方面遇到了麻烦。

以下是我的课程:

[Table("PROJTABLE")]
    public class Certifikat {
        [Key]
        public long Recid { get; set; }

        public String Projid { get; set; }           
        public virtual StandardAndScope StandardInfo { get; set; }
}

[Table("DS_CRT_PROJSTANDARDSCOPE")]
    public class StandardAndScope {
        //[Key]
        //public long RECID { get; set; }
        [Key]
        public String Projid { get; set; }

        public String Standard { get; set; }
        public String Scope { get; set; }
    }

由于我无法控制数据库,因此我无法更改密钥和ID以支持约定,而且我仍然坚持使用此设置。

我的问题是,Certifikat CAN与一个StandardAndScope有关系。两个表中的键都称为Projid - 但这并不是数据库中两个表的主键。

我真正想要的是:“certifikat c在c.Projid = s.Projid上加入standardandscope”

如何使用流畅的api完成此操作?

1 个答案:

答案 0 :(得分:1)

我认为你正在寻找这样的东西:

var result = dataContext.Certifikats
    .Join(dataContext.StandardAndScopes,
        c => c.Projid,
        s => s.Projid,
        (c, s) => new
        {
            Certifikat = c,
            StandardAndScope = s
        });

dataContextDbContext类的实例。

相关问题