0

This article is really great and awesome. This is from the topic "ASP.NET MVC 2.0 Implementation of searching in jqgrid" - ASP.NET MVC 2.0 Implementation of searching in jqgrid.

But right now I was facing searching problem when I added a field with small integer data type. The field added with data type of small integer will serve as Status. Lets say the value one(1) is for Active and value two(2) is for Inactive.

When I type 1 or 2 from the text box it was throwing an error of

System.Data.Entity: The argument types 'Edm.Int16' and 'Edm.String' are incompatible for this operation. Near equals expression, line 6, column 12.

Thank you in advance.

Community
  • 1
  • 1
xmox
  • 43
  • 1
  • 5

1 Answers1

0

I am glad that my old answer was helpful for you. I suppose you have problem near the line

// TODO: Extend to other data types

In the code which I included in the answer I shown that propertyInfo.PropertyType.FullName hold the information about the datatype of the entity's property. In the code I used only two types: string and 32-bit integer. In case of 32-bit integers I made the corresponding data parsing with respect of Int32.Parse:

String.Compare (propertyInfo.PropertyType.FullName,
                "System.Int32", StringComparison.Ordinal) == 0 ?
    new ObjectParameter ("p" + iParam, Int32.Parse(rule.data)

You should replace " ? : " operator with case where you test propertyInfo.PropertyType.FullName for more data types. For example in case of smallint SQL type you should use System.Int16, in case of tinyint it should be System.Byte, The sbyte SQL datatype corresponds to System.SByte and so on. If you would use as the second parameter of ObjectParameter correct datatype all should work correctly

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Hi Oleg, Thank you for your immediate response. It works now. I just made the field property nullable to false. Your answer code really helps me a lot :) – xmox Nov 01 '11 at 01:13
  • Hi Oleg, is there a way to search from outside the grid? Let's say I would like to search Vote & Title from there with the submit button. Pls let me know how it works. Thanks – xmox Nov 09 '11 at 22:09
  • @xmox: The searching is nothing more as setting `search: true` parameter of jqGrid, extending `postData` parameter of jqGrid with `filter` which described the searching criteria and call of `.trigger('reloadGrid')` to force grid reloading corresponds to the new searching criteria. See [here](http://stackoverflow.com/questions/5272850/is-there-an-api-in-jqgrid-to-add-advanced-filters-to-post-data/5273385#5273385) or [here](http://stackoverflow.com/questions/4492963/jqgrid-client-side-searching/4509018#4509018) – Oleg Nov 09 '11 at 22:33
  • Hi Oleg, when I shift converted the sample "ASP.NET MVC 2.0 Implementation of searching in jqgrid" into code first it does not work. I was trap on this script => ObjectQuery filteredQuery = (f == null ? db.vend_details : f.FilterObjectSet(db.EntityTable)); Is there's a way I can be able to convert it to code first? thanks – xmox Jul 07 '12 at 06:42
  • @xmox: The problem is that the definition of entities are changed in case of usage of the code first. So you should just define objects which you use in Queries in another way directly: `ObjectSet questions = context.CreateObjectSet("Questions");`. See comments to [the answer](http://stackoverflow.com/a/11247448/315935) which describes the same problem. – Oleg Jul 07 '12 at 08:03
  • Thanks but still doesn't work. Do you have a sample code Mvc+ JqGrid+CodeFirst? Just like the code on ASP.NET MVC 2.0 Implementation of searching in jqgrid – xmox Jul 10 '12 at 00:41
  • Hi Oleg, Please see separate link [Mvc, JqGrid and EF Code First with Filters function](http://stackoverflow.com/questions/11405932/mvc-jqgrid-and-ef-code-first-with-filters-function) for more details about my problem in code first. thanks – xmox Jul 10 '12 at 02:51