---
title: "How to use object query with a WHERE, AND to retrieve entity record, entity framework"  
description: "How to use object query with a WHERE, AND to retrieve entity record, entity framework"  
author: "Anonymous User"  
published: 2015-01-19  
updated: 2015-01-19  
canonical: https://www.mindstick.com/forum/12875/how-to-use-object-query-with-a-where-and-to-retrieve-entity-record-entity-framework  
category: "asp.net"  
tags: ["c#", ".net", "vb.net", "entity framework"]  
reading_time: 2 minutes  

---

# How to use object query with a WHERE, AND to retrieve entity record, entity framework

I [am trying](https://answers.mindstick.com/qa/36834/which-two-programming-languages-should-i-master-in-if-i-am-trying-to-get-into-google-or-facebook) to add and AND [condition](https://www.mindstick.com/forum/12711/select-query-with-and-condition) to my [entity framework](https://www.mindstick.com/articles/1566/crud-operations-using-entity-framework-code-first-approach) [where clause](https://www.mindstick.com/interview/1909/when-do-you-use-where-clause-and-when-do-you-use-having-clause), but the way I am doing it is not working. Can [anyone](https://www.mindstick.com/articles/23207/how-to-find-the-best-fit-job-for-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).FirstOrDefault()

The error I get reads as:

[Conversion](https://www.mindstick.com/forum/1734/conversion-from-32-bit-integer-to-4-chars) from [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp) "it.Recipe_Id=11" to type 'Long' is not valid.

Thank you very much.

## Replies

### Reply by Anonymous User

I would try to use the built in linq if you can. It will check your values at compile time for you and you won't get nasty surprises at run time. You can use magic-strings of course but why not use one of the best features of of an ORM? Imagine updating a tables field type, the compiler will automatically let you know every place you need to update your code. Instead of having forgetting about one and then having it crash here and there.

If you're querying a single table, often it's easier to put the 'wheres' inside the FirstOrDefault();

```
Dim myRecipeStepsHistory = myContext.RefineRecipeStep         .FirstOrDefault(x => x.Recipe_Id.Equals(strRecipeId) &&                              x.IngredientItemNumber == strIngredientNumber); if(myRecipeStepHistory != null){     // }
```

You may have to cast your values so it matches the correct data type for Recipe_Id and IngredientItemNumber.


---

Original Source: https://www.mindstick.com/forum/12875/how-to-use-object-query-with-a-where-and-to-retrieve-entity-record-entity-framework

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
