我正在使用此处找到的动态 Linq 库:
http://speakingin.net/2008/01/08/dynamic-linqparte-1-usando-la-libreria-de-linq-dynamic/
http://msdn.microsoft.com/en-us/vstudio//bb894665.aspx
我的 DAL 中有以下代码:
public IQueryable<RequestBase> GetRequestByCustomQuery(string strql)
{
return _context.RequestBases.Where(strql);
}
我的页面中有以下代码:
protected void BtnOpenReport_Click(object sender, EventArgs e)
{
var list = RequestBaseBL.GetRequestByCustomQuery("RequestNumber = 12");
GrvResults.DataSource = list;
GrvResults.DataBind();
}
我省略了所有其他层,但是有一个 BL,然后是 Dal Facade,然后是 DL,但他们所做的只是将字符串传递到最后一层,即 DAL。
我得到了例外
Operator '=' incompatible with operand types 'String' and 'Int32'
对象是这样的:
public class RequestBase
{
public int RequestBaseId { get; set; }
public string CurrentStatus { get; set; }
public string RequestNumber { get; set; }
public DateTime RequestDate { get; set; }
public bool IsOnHold { get; set; }
public virtual Dealer Dealer { get; set; }
public virtual Requester Requester { get; set; }
public virtual Vehicle Vehicle { get; set; }
public virtual ICollection<Attachment> Attachments { get; set; }
public virtual ICollection<WorkflowHistory> WorkflowHistories { get; set; }