栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

实体框架一对一导航属性未加载

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

实体框架一对一导航属性未加载

因此我想出了很多错误,但这是对我有用的解决方案。您无需实例化单个导航属性。这将使其始终为空。如果它是对象的ICollection,则仍然需要实例化Navigation属性。还有其他一些小事情。谢谢您的帮助。

public partial class Submission{public int Keytbl { get; set; }    public int Company { get; set; }    public virtual tbl_lst_Company tbl_lst_Company{ get; set; }        }public partial class tbl_lst_Company{       public tbl_lst_Company() {        this.Submissions = new List<Submission>();}    public int CompanyID { get; set; }    public string Company { get; set; }    public virtual ICollection<Submission> Submissions { get; set; }}public tbl_lst_CompanyMap(){    // Primary Key    this.HasKey(t => t.CompanyID);    // Properties    this.Property(t => t.Company)        .IsRequired()        .HasMaxLength(150);    // Table & Column Mappings    this.ToTable("tbl_lst_Company");    this.Property(t => t.CompanyID).HasColumnName("CompanyID");    this.Property(t => t.Company).HasColumnName("Company");}public SubmissionMap(){    // Primary Key    this.HasKey(t => t.Keytbl);    // Table & Column Mappings    this.ToTable("Submissions");    this.Property(t => t.Keytbl).HasColumnName("Keytbl");    this.Property(t => t.Company).HasColumnName("Company");    this.HasOptional(t => t.tbl_lst_Company)    .WithMany(t => t.Submissions).HasForeignKey(d => d.Company);}[TestMethod]public void test_lazy_loading() {    using (var db = new SubmissionContext()) {    var subs = (from s in b.Submissions       select s);    var x = subs.First().tbl_lst_Company;    Assert.AreEqual(x, null, "Lazy Loading Failed");    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/372073.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号