你知道为什么Linq2Sql没有为具有复合PK的对象使用身份缓存吗?通过这篇msdn文章(https://msdn.microsoft.com/en-us/library/dd627203(v=vs.100).aspx),可以满足使用缓存的所有要求。
示例代码:
using (var context = new OrderingDataContext())
{
var o1 = context.Orders.SingleOrDefault(x => x.SiteId == 1 && x.OrderId == 1119);
//cache will not be used - PK SiteId + OrderId
var o2 = context.Orders.SingleOrDefault(x => x.SiteId == 1 && x.OrderId == 1119);
var s1 = context.Sites.SingleOrDefault(x => x.SiteId == 1);
//cache will be used - PK SiteId
var s2 = context.Sites.SingleOrDefault(x => x.SiteId == 1);
}
由于 薇罗尼卡