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

  • Question

  • User1655654435 posted


    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() 

    Tuesday, September 15, 2020 8:39 AM

All replies