c# - Create dynamic LINQ query expression at runtime which translates into a parameterized SQL query for nullable types -


This question is related to my

I want to make my custom expression for IQueryable in a nutshell. To achieve this goal, I wrote the next code.

  Public stable IQueryable & lt; T & gt; Filter Aquales & lt; T, TLL & gt; (This IQueryable & lt; T & gt; qSource, expression & lt; Func & lt; t; TLL; Field, TV value) {var fieldFilter = ExpressionClosureFactory.GetField (value); Var constraint = expression. Aqual (field. Body, field filter); Apply Return (qSource, Obstacle, Zone. Parameter); } Private Stable IQueryable & lt; T & gt; Apply & lt; T & gt; (IQueryable & lt; T & gt; qSource, Expression Barrier, ReadOnlyCollection & lt; Parameter Exposure & gt; Parameter) {var predicateFrom = Expression Lambda & lt; Func & lt; T, bool & gt; & Gt; (Hurdle, parameter); Return qSource.Where (predicateFrom); } Public Speaking Expression Clausfactree {Public Status Member Expert Gatefield & lt; TVLUE & gt; (TV value) {Turn Off = New Expression Closer Field & lt; TVLAT & gt; {ValueProperty = value}; Return expression.fild (expression constant, "value property"); } Class expression closer field & lt; T & gt; {Public T-value property; }}  

This works fine and the parameter generates SQL queries. But there is some problem with nullable type next code

  int testFilter = 1; Var testExtension = Reference .set & lt; Users & gt; () .FilterEquals (u = & gt; u.IntNullable, testFilter); Translated into  

  SELECT [extent1]. [ID] AS [ID], [Extent 1]. [Int'table] from AS [integration]] [user] AS [ext1] where ([ext. 1]. [Intelligible] = @ P__lineac__0) or (([Extent 1]. [Int'lable] IS Nouvel) and ( @ P_LLK 0 is the IS tap))  

and without the extension code

  int testFilter = 1; Var testUsual = context.Set & lt; Users & gt; (). Where (u = & gt; u.IntNullable == testFilter); Translated into  

  SELECT [extent1]. [ID] AS [ID], [Extent 1]. [ENTATTHABLE] AS [integration] by [dBO]] [user] AS [EXSTANT 1] where [EXTEN 1]. [Intubulble] = @ P_LLK__0  

As we can see in the standard scenario, the unknown or clause does not occur. So how can I get in my code?

Update

I changed the filter avelles and it now works as expected, but this code looks like a hack

  Public stable IQueryable & lt; T & gt; Filter Aquales & Lt; T, TLL & gt; (This IQueryable & lt; T & gt; qSource, Expression & lt; Funk & lt; t, TvLue; Field, TV Price) {Expression Field Filter; Type the built-in Var = null-worthy. GETUnderlyingType (field.Body.Type); If (underlying type! = Null) {var convert conversion = expression. Convert (Expression ClosureFactory.GetField (Value), built-in type); FieldFilter = Expression Convert (convertible line, field body type); } Other {fieldFilter = ExpressionCloseFactory.GetField (value); } Var constraint = expression. Aqual (field. Body, field filter); Apply Return (qSource, Obstacle, Zone. Parameter); }  


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -