本文整理汇总了C#中DataContext.Map方法的典型用法代码示例。如果您正苦于以下问题:C# DataContext.Map方法的具体用法?C# DataContext.Map怎么用?C# DataContext.Map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataContext
的用法示例。
在下文中一共展示了DataContext.Map方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: when_using_ef
public when_using_ef()
{
var mapperContainer =
new MapperContainer()
.Register<Person, PersonEntity>(
(f, t, c) =>
{
c.Map(f.Name, () => t.Name);
c.MapAll(f.Addresses, () => t.Addresses);
})
.Register<Name, NameEntity>(
(f, t, c) =>
{
t.First = f.First;
t.Last = f.Last;
}
)
.Register<Address, AddressEntity>(
(f, t, c) => { t.Name = f.Name; }
);
Database.SetInitializer(new DropCreateDatabaseIfModelChanges<DataContext>());
_dataContext = new DataContext(mapperContainer);
_from = new Person
{
Name = new Name {First = "Person"},
Addresses = new[]
{
new Address {Name = "Keep"},
new Address {Name = "New"}
}
};
_to = _dataContext.Create<PersonEntity>();
_to.Name = new NameEntity {First = "Overwite"};
_to.Addresses = new[]
{
new AddressEntity {Name = "Keep"},
new AddressEntity {Name = "Delete"}
};
_dataContext.SaveChanges();
var personId = _to.Id;
_dataContext.Map(_from, () => _to);
_dataContext.SaveChanges();
_dataContext = new DataContext(mapperContainer);
_to = _dataContext
.People.Include(p => p.Addresses)
.Single(p => p.Id == personId);
}