c# - Creating an IQueryable to Equal int32? -


I am trying to create a query extension which will compare a null qualified int sql column value with the value. But I am already struggling more than 8 hours to find solutions to any work.

I've got a lot of help on this side. But not all comments helped me.

I have changed the code several times, but anything seems to work. I would like to create something like WHERE ManagerID IN (10,20,30)

main code

  IQueryable & lt; Users & gt; Query = _context.CreateObjectSet & lt; Users & gt; (); query = query.IsMember (a => a.ManagerID, new Int32? [] {10,20,30}); Return query. Toolist ();   

While currently performing the query. It gives me a return

Unable to create a constant value type 'System.Object'. Only primitive types or counting types are supported in this context.

  Public stable IQueryable & lt; T & gt; IsMember & LT; T & gt; (The IQueryable & lt; t & gt; source & lt ;? t, int32 & gt; & gt; stringProperty, parameter int32 [] searchTerms of function?) {If (searchTerms == null SearchTerms.Any ()!) {Return source; } Expression or expression = zero; FourSearch (Search Search in Search Search) {var searchTermExpression = Expression.Constant (searchTerm, typeof (object)); // & lt; & Lt; --- This will be cast, it now contains a primitive typeExpression = Expression.Call (stringProperty.Body, typeof (Int32) GetMethod ("par"), searchTermExpression?.); Or expression = builder express (or expression, includes the expression in it); } Var completeExpression = Expression.Lambda & lt; Func & lt; T, bool & gt; & Gt; (Or expression, string proprietary parameter); Return Source. Where (period); } Personal Static Expression BuildOrpress (Expression Addition to Current Accretion, Expression Expression) {Existing Existing Expiration == is Empty? Add to the expression: expression. ORL (Existing expression, add for expression); }   

The line is continuously marked to give another datatype, actually causing the problem, but if I do not match it as type object it will not work, expression, Are int32? Datatip

Can anyone help me?

Thanks

=================================== ===========================

ADDITIONAL INFORMATION

It was a really big picture, I just want to make something more dynamic Which can also be used on other projects.

I would like to use some of the functions that will look attractive to all the multiverse.

  query = Query.Like (a => a.UserName, Filter.UserName, true); Query = query.Equals (a => a.UserTown, filter.UserTown, true); query = query.IsMember (a = & gt; a.Division, filter.Division); // is an array of possible divisions   

This works fine for the same and equal to which the string is based I want to create a similar product for the (nullable) integers

I was inspired by the following post that created a search function (which I named for my project)

I wanted to make others equal. The last bullion has to verify that it is worth noting in the column or not.

The reason for using an extension is that I have many filters in my filter page. With this extension, I would easily check in the beginning and similar function of my like if a filter checked my filter was 20x of a value without if it was given without

  public static IQueryable. & Lt; T & gt; As & lt; T & gt; (String.IsNullOrEmpty (SEARCHTERM)) (return to this IQueryable & lt; t & gt; source & quot; function & lt; t, string & gt; string string; string string; SEARCHTERM; string; Query; }    

It is not clear why you want to create this extension because you simply Can write something like:

  query.Where (.username => (new [] {10,20,30}) (User.ManagerId).) To create the list (); Although   

However, assuming the case of actual usage is somewhat more complex than the example given by you, can not you create your own expression, or even a continuous int32 Comparison against or compare against the tap, depending on whether the searchTerm.HasValue () was correct?

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -