Click here to Skip to main content
14,027,427 members
Rate this:
Please Sign up or sign in to vote.
See more: , +

How to check id exist or not generic repository pattern core 2.1 ?

because i have more than 10 controllers so that i need to write function check

if id on table exist or not .

like that
if (!EmployeeExists(emp.EmployeeId))
                        return NotFound();

What I have tried:

I try that by this not work

bool CheckIfEntityExistsByEntityId(Expression<Func<T, bool>> expr);
public bool CheckIfEntityExistsByEntityId<T>(Expression<Func<T, bool>> expr)
            return dbSet.Any(u => expr);

I have compile error on expr
Richard MacCutchan 8-Feb-19 11:18am
"I have compile error on expr"
You have been told enough times already: if you get an error message then you need to tell us what it is; we cannot guess.
Richard Deeming 12-Feb-19 13:11pm
At the risk of contradicting the other Richard:
public bool CheckIfEntityExistsByEntityId<T>(Expression<Func<T, bool>> expr)

Why have you re-declared the generic type parameter on the method? You should be using the type parameter from the class instead.
public bool CheckIfEntityExistsByEntityId(Expression<Func<T, bool>> expr)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web06 | 2.8.190419.4 | Last Updated 8 Feb 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100