Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

How to check if something is true but not return anything else but a bool

$
0
0

Hi,

i'm trying to write a query in entity framework core to check if a record is in the db, but i don't need to return any data. is this possible?

the logic would be something like this:

bool check = _context.Person.Where(i => i.ID == 22 & i.Postcode == 8014)

But i cant just return as bool, but rather I need to use FirstOrDefault and take the data. I know there is a function in linq where i can use Any(), but i can't get the syntax right. 

I just want to learn if there is a way to check things without returning data. Now i return a model with the id and postcode and just checks if they are correct: var data = (from e in _context.Person where e.ID == 22 & e.Postcode == 8014 select new checkmodel { id = e.ID, postCode = e.Postcode}).FirstOrDefault() 


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>