我需要来自2个不同数据库的数据。我试过以下
var User = (from U in _db.TblUsers
where U.IsAdmin == false
select U).ToList();
var AspNewsUser = (from A in _dbAspNet.aspnet_Users
select A).ToList();
var result = (from U in User
join A in AspNewsUser
on U.UserID equals A.UserId
select U);
但是我收到以下错误消息
join子句中某个表达式的类型不正确。 调用“加入”时类型推断失败。
答案 0 :(得分:1)
正如您在table schema of aspnet_Users中看到的那样,Userid
是uniqueidentifier
(映射到实体框架中的GUID)。我敢打赌TblUsers.UserID
有不同的类型(如int
)。
答案 1 :(得分:0)
使用投影,使它们成为相同的匿名类型。
var Users = (from U in _db.TblUsers
where U.IsAdmin == false
select new { UserID = U.UserID }).ToList();
var AspNewsUsers = (from A in _dbAspNet.aspnet_Users
select new { UserID = A.UserID }).ToList();
var result = (from i in Users join o in AspNewUsers on i.UserID equals o.UserID).ToList();