1

我需要来自 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 子句中的表达式之一的类型不正确。对“加入”的调用中的类型推断失败。

4

2 回答 2

1

正如您在aspnet_Users 的表架构中看到的那样,Userid是一个uniqueidentifier(映射到实体框架中的 GUID)。我敢打赌,TblUsers.UserID它有不同的类型(如int)。

于 2012-11-25T12:40:09.317 回答
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();
于 2012-11-25T07:11:23.940 回答