具有不同列名的实体类型配置映射 [英] Entity Type Configuration Mapping with different column name

查看:84
本文介绍了具有不同列名的实体类型配置映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



假设我有以下结构。





Hi All

Suppose I have following structure.


public class A
{
	public int ID{get;set;}
	public string Name{get;set;}
	public List< B> BList{get;set;}
}
public class B
{
	public int ID{get;set;}
	public int AID{get;set;}
	public string Name{get;set;}
	public A AObject{get;set;}
}
public class AMap:EntityTypeConfiguration<A>
{ 
   public AMap()
   {
	this.ToTable("ATable");

	this.HasKey(x => x.ID);
   }
}
public class BMap:EntityTypeConfiguration< B>
{
   public BMap()
   {
	this.ToTable("BTable");

	this.HasKey(x => x.ID);

	this.Property(x => x.AID).IsRequired();
	this.HasRequired(x => x.AObject).WithMany(x => x.BList).HasForeignKey(x => x.AID);
   }
}





当我获得ATable的单个记录时,它应该绑定A中的BTable记录列表对象,但我得到BList null。



我在这里缺少什么?



When I get single record of ATable then it should bind list of BTable records in A object but I am getting BList null.

What am I missing here?

推荐答案

添加一个构造函数对于A类并初始化List BList



public A()

{

this.BList =新列表< B> ();

}
add a constructor for class A and initialize List BList

public A()
{
this.BList = new List < B > ();
}


这篇关于具有不同列名的实体类型配置映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆