Linq to sql 使用LinqtoSql返回域映射列表
我该怎么做 与此相反:Linq to sql 使用LinqtoSql返回域映射列表,linq-to-sql,domain-driven-design,Linq To Sql,Domain Driven Design,我该怎么做 与此相反: var people= (from p in db.people select new Person{ id=p.id, name=p.name }).ToList(); 我想这样做: var
var people= (from p in db.people select new Person{
id=p.id,
name=p.name
}).ToList();
我想这样做:
var people= (from p is db.people select new Person {
***MAPTODOMAIN(p)***
}).ToList();
假设您模型中的Person是一个不在Linq2SQL数据上下文中的域类,并将类AppUser替换为数据上下文中的类(为了清楚起见,在您的示例中,名称非常相似),类似这样的操作将有效:
var people = (from p in db.AppUsers select MapPerson(p)).ToList();
在代码中的其他地方使用类似于此的方法:
private Person MapPerson(AppUser user)
{
return new Person {Id = user.Id, Name = user.Name};
}