【发布时间】:2014-02-06 15:33:50
【问题描述】:
我得到了一个
DbComparisonExpression requires arguments with comparable type
以下 LINQ to Entity 查询出错:
jobDetails.pdata = db.JobBoardUsers.Where(c => c.id.Equals(jbid)).Select(c => new JobBoardUserProfileModel() { ID = c.id, userid = c.userid, firstname = c.firstname, lastname = c.lastname, PostalCode = c.passcode, phone = c.phone, JobDescription = c.desiredjobtitle, resumetext = c.resumetext, savedresume = c.savedresume }).ToList();
除 ID (Int) 外,所有其他列都是 Varchar。在 EF(模型浏览器)中,ID 列显示为 Int32,其余为字符串。此外,该表确实有一个主键。
这是 JobBoardUserProfileModel 模型:
public class JobBoardUserProfileModel
{
public int ID { get; set; }
public string userid { get; set; }
public string firstname { get; set; }
public string lastname { get; set; }
public string PostalCode { get; set; }
public string phone { get; set; }
public string JobDescription { get; set; }
public string savedresume { get; set; }
public string resumetext { get; set; }
}
似乎一切都完美对齐。为什么会出现此错误?
【问题讨论】:
-
jbid的类型是什么?为什么不使用c.id == jbid? -
谢谢 Habib,你找到了我的问题。我什至没有将 jbid 视为可能的问题,但确实它是一个字符串,并且应该针对“userid”而不是“id”进行评估!
标签: c# linq entity-framework visual-studio-2012