我想创建一个DDD存储库,它返回与Linq到SQL基础类匹配的IQueryable实体,减去任何关系.我可以轻松地返回实体减去与Linq选择新{field,field,...}投影的关系.如何编写Repository Entity类?如何从具有存储库类而不是Linq to SQL类的存储库中返回一个对象,并且仍然使用Linq选择中的多个实体填充它?我如何在ViewModel中引用此返回的类?
我对此很新,因此显而易见的错误.我是否错过了船,只应从存储库返回完整的实体,而不是投影?在从存储库发送之前,我仍然需要删除Linq to SQL关系.我完全不在基地吗?我真的想保留IQueryable数据类型.
例如,我的存储库中的Linq to SQL代码:
public class MiniProduct
{
public MiniProduct( string ProductNo, string Name, string Description, double Price)
{ this.ProductNo = ProductNo;
this.Name = Name;
this.Description = Description;
this.Price = Price;
}
}
public IQueryable<MiniProduct> GetProductsByCategory( string productCategory)
{
return ( from p in db.Products
from c in db.Categories
from pc in db.ProductCategories
where c.CategoryName == productCategory &&
c.CatID == pc.CatID &&
pc.ProductID == p.ProductID
select new { p.ProductNo, p.Name, p.Description, p.Price } ); …Run Code Online (Sandbox Code Playgroud)