2
我有,當我把一切都在一個聲明中完美的作品查詢:不能隱式轉換類型System.Linq.IQueryable <AnonymousType#1> System.Linq.IQueryable <AnonymousType#2>
var rs = db.SerialNumbers
.Join(db.ProductLines, sn => sn.ProductLineId, pl => pl.Id, (sn, pl) => new { pl.Id, pl.Category, sn.UserId })
.Where(sn => sn.UserId == userId)
.Select(sn => new { sn.Id, sn.Category })
.Distinct();
但是我需要爲UserId添加條件。我只想過濾,如果有一個在用戶id的條目,即用戶ID> 0,所以我改變查詢到:
var rs = db.SerialNumbers
.Join(db.ProductLines, sn => sn.ProductLineId, pl => pl.Id, (sn, pl) => new { pl.Id, pl.Category, sn.UserId });
if(userId > 0)
{
rs = rs.Where(sn => sn.UserId == userId);
}
rs = rs.Select(sn => new { sn.Id, sn.Category });
我得到的編譯此錯誤:
不能隱式轉換類型
System.Linq.IQueryable<AnonymousType#1>
到System.Linq.IQueryable<AnonymousType#2>
我該怎麼辦?