求教Include 方法在 linq to sql / entity framwork使用方法

bigbaddy007 2016-10-26 04:58:44
Customer 类里有


public int? CityId { get; set; }

public virtual City City { get; set; }


代码如下,Customers表里有CityID, 然后 “Include("Cooperations").Include("Staff").Include("City")” 后
public virtual City City { get; set; } 这个属性始终没有赋值,就是Include("City") 没有被执行。

除非 我在第一行写成 “var query = from a in dbContext.Customers.Include("Cooperations").Include("Staff").Include("City").ToList()”

但是这样运行时又报错。 求指教。。。。。。。。。


var query = from a in dbContext.Customers.Include("Cooperations").Include("Staff").Include("City")
join b in dbContext.Business
on new { Cus = a.ID, Stf = a.StaffID } equals new { Cus = b.CustomerID == null ? 0 : b.CustomerID.Value, Stf = b.StaffID } into t
join c in dbContext.Provinces on (a.CityId == null ? 0 : a.City.ProvinceID) equals c.ID into x

where staffids.Contains(a.StaffID == null ? -1 : a.StaffID.Value)
select new BusinessVM
{
Customer = a,
Business = t.Where(p => (p.CreateTime > parm.startdate.Value && p.CreateTime < parm.enddate.Value)),
Provienc = "江南"
};
return query.OrderByDescending(u => u.Customer.ID).Skip(itemIndex).Take(pageSize).ToList();
...全文
1264 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
卿文刚 2016-12-08
  • 打赏
  • 举报
回复 1
linq to sql 和entityframwork不能同时使用。。 参考这里:http://www.yuanjiaocheng.net/entity/tixijiegou.html
bigbaddy007 2016-11-03
  • 打赏
  • 举报
回复
linq to sql 和entityframwork不能同时使用。。
bigbaddy007 2016-10-26
  • 打赏
  • 举报
回复
人工置顶!

8,492

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 LINQ
社区管理员
  • LINQ
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧