这个项目让我发疯 ;-) 我正在尝试做一个简单的查询来连接两个表
我有以下内容:
存储库类方法
public IQueryable<ADPerson> FindAll(string UserId)
{
return (from p in db.ADPerson
select p);
}
在我的控制器中:
var ADPersonList = from o in ADPersonDB.FindAll(GetUserId())
join c in MSDNTypeDB.FindAll(GetUserId()) on o.MsdnTypeId equals c.MsdnTypeId
select new ADPerson()
{
AdPersonId = o.AdPersonId,
SamAccountName = o.SamAccountName,
Description = o.Description,
DisplayName = o.DisplayName,
UserPrincipalName = o.UserPrincipalName,
Enabled = o.Enabled,
LastUpdated = o.LastUpdated,
OnlineAssetTag = o.OnlineAssetTag,
MsdnTypeId = o.MsdnTypeId,
MsdnSubscription = c.MsdnTypeDescription,
};
我不断收到错误消息:
{"The specified LINQ expression contains references to queries that are associated with different contexts."}
我还尝试添加到存储库类:
存储库类方法
public IQueryable<ADPerson> FindAll(string UserId)
{
//return (from p in db.ADPerson
// select p);
var query = from o in db.ADPerson
join c in db.MsdnTypes on o.MsdnTypeId equals c.MsdnTypeId
select new ADPerson()
{
AdPersonId = o.AdPersonId,
SamAccountName = o.SamAccountName,
Description = o.Description,
DisplayName = o.DisplayName,
UserPrincipalName = o.UserPrincipalName,
Enabled = o.Enabled,
LastUpdated = o.LastUpdated,
OnlineAssetTag = o.OnlineAssetTag,
MsdnTypeId = o.MsdnTypeId,
MsdnSubscription = c.MsdnTypeDescription,
};
return query;
}
在两个表之间做一个简单的连接并在实体框架中填充变量真的很难吗
谢谢