【发布时间】:2011-08-03 15:23:22
【问题描述】:
我有以下型号。
class Parent
{
int ParentId (identity column) { get; set; }
string ParentName { get; set; }
virtual ICollection<Child> Children { get; set; }
}
class Child
{
int ChildId (identity column) { get; set; }
string ChildName { get; set; }
int ParentID { get ; set; } //foreign key to Parent(ParentID)
}
如何在单个事务中向我的父母和孩子插入几行?基本上我想获得在父级上生成的标识(比如我在父级中插入一行)并插入具有该值的子行? 如何使用 Code First 实现这一点?
【问题讨论】:
标签: entity-framework code-first ef-code-first