metropia
asked on
entity framework, how to use object query with a WHERE, AND to retrieve entity record.
Hello,
I am trying to add and AND condition to my entity framework where clause, but the way I am doing it is not working. Can anyone show me how to do this the correct way please? Before adding the AND condition, the code worked fine.
Dim myRecipeStepsHistory = myContext.RefineRecipeStep .Where("it .Recipe_Id =" & strRecipeId And "it.IngredientItemNumber=" & strIngredientNumber).First OrDefault( )
The error I get reads as: Conversion from string "it.Recipe_Id=11" to type 'Long' is not valid.
Thank you very much.
I am trying to add and AND condition to my entity framework where clause, but the way I am doing it is not working. Can anyone show me how to do this the correct way please? Before adding the AND condition, the code worked fine.
Dim myRecipeStepsHistory = myContext.RefineRecipeStep
The error I get reads as: Conversion from string "it.Recipe_Id=11" to type 'Long' is not valid.
Thank you very much.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi metropia;
In order to answer your question we need to know the data type of the following.
Database types for
Recipe_Id
IngredientItemNumber
In your code for
strRecipeId
strIngredientNumber
In order to answer your question we need to know the data type of the following.
Database types for
Recipe_Id
IngredientItemNumber
In your code for
strRecipeId
strIngredientNumber
ASKER
got it to work.
Dim myRecipeStepsHistory = myContext.RefineRecipeStep.FirstOrDefault(Function(x) x.Recipe_Id = intRecipeId AndAlso x.IngredientItemNumber = strIngredientNumber)
The original query you were using was doing the query with Query Builder syntax but in your latest post you used method syntax. The reason I was asking for the data types is that string parameters need to be inclosed ' ' and I believe that was the issue but not knowing what was a string and what were other types I was not able to infer from the statement.
ASKER
Sorry I did not mean not to answer your question.
I would be interested in knowing the alternative solution, following original post.
Database types for
Recipe_Id < int
IngredientItemNumber < nvarchar(20)
In your code for
strRecipeId < string
strIngredientNumber < string
Thank you much.
I would be interested in knowing the alternative solution, following original post.
Database types for
Recipe_Id < int
IngredientItemNumber < nvarchar(20)
In your code for
strRecipeId < string
strIngredientNumber < string
Thank you much.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I tried your recommendation but I get:
for line:
Open in new window