I have a function to which I pass a string and then use linq to entity to check if the string value that I passed already exists in the database. For This purpose I have written this function.
public static bool UserExistChk(String StrUserId) {
using (SBVEntities dbcontx = new SBVEntities())
{
return dbcontx.Users.Contains(dbcontx.Users.FirstOrDefault(e => e.UserID == StrUserId));
}
}
But I get error– Unable to create a constant value of type ‘MySBVApp.Models.User’. Only primitive types (‘such as Int32, String, and Guid’) are supported in this context.
Please help I am new to entity framework and linq.
You can use the
Anyextension method for this: