Dynamic linq query not working

I am using the Dynamic Linq library found here:

http://speakingin.net/2008/01/08/dynamic-linqparte-1-usando-la-libreria-de-linq-dynamic/

http://msdn.microsoft.com/en-us/vstudio//bb894665.aspx

I have the following code in my DAL:

public IQueryable<RequestBase> GetRequestByCustomQuery(string strql)
            {
                return _context.RequestBases.Where(strql);
            }

And I have the following code on my page:

protected void BtnOpenReport_Click(object sender, EventArgs e)
        {
             var list = RequestBaseBL.GetRequestByCustomQuery("RequestNumber = 12");
            GrvResults.DataSource = list;
            GrvResults.DataBind();
        }

I omit all the other layers, but there is BL, then Far Facade and DL, but all they do is pass the string to the last DAL level.

I get an exception

Operator '=' incompatible with operand types 'String' and 'Int32' 

The object is as follows:

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; }
+5
source share
3 answers

Perhaps because your RequestNumber is defined as a string in the object. But in request "RequestNumber = 12" 12 is considered a number.

Try with "RequestNumber == \"12\""

, , .

+12

,

"RequestNumber = 12"

"RequestNumber = '12'"

Becuase RequestNumber - string. '', , int

Edit

"RequestNumber == \"12\"" escape-

+2

I realized that your "RequestNumber" is a string and will have to use Equals ("12"), try this, it should definitely work.

RequestNumber.Equals ("12")

Happy coding !!!

0
source

All Articles