三个表:
Category - CID, CName,CParentID (when CParentID=0, its a Category; when CParentID > 0, its a SubCategory)
Product - PID,Title, Desc etc
Category_Product - CPID, CID, PID
功能:
public List<T> GetProductCategory<T>(int id)
{
var Query = from ProductTable in objProductDataContext.Products
join CPTable in objProductDataContext.CategoryProducts on ProductTable.ProductID equals CPTable.ProductID
join CategoryTable in objProductDataContext.Categories on CPTable.CategoryID equals CategoryTable.CategoryID where ProductTable.ProductID==id
select new { ProductTable, CPTable, CategoryTable };
return Query;
}
我需要将此数据返回给控制器。我怎样才能做到这一点?我读到了创建一个单独的类,但我不确定在这种情况下我会怎么做。标题是我得到的当前错误。