in the stored procedure we can verify that the record exists or is not using the following query for fast performance
if EXISTS ( Select 1 from Table_Name where id=@id )
But what about the Linq request. right now i have to store the whole data in an object like this
UserDetail _U=db.UserDetails.where(x=>x.id==1).FirstOrDefault();
Any solution?
Use Linq Anyiebool exist = db.UserDetails.Any(x => x.id == 1);
Any
bool exist = db.UserDetails.Any(x => x.id == 1);
if(db.UserDetails.Any(x => x.id == 1)) { var userDetail = db.UserDetails.FirstOrDefault(x => x.id == 1); }
Just check
if(_U == null)
This way you get what you want in a single request, and you do not need to execute the add request, for example
db.UserDetails.Any(x => x.id == 1)
bool exist = db.UserDetails.Where(x=>x.id==1).Any(); if(exist){ //your-code }else{ //your-code }
, . .
UserDetails objUserDetails =db.UserDetails.FirstOrDefault(x => x.id == 1); if(objUserDetails==null) { // Do something } else { // do something with objUserDetails }
var qry = db.User_Detail.Where(x => x.User_Id == 1).FirstOrDefault(); if(qry !=null) { // Do something } else { return false; }
...
Source: https://habr.com/ru/post/1676624/More articles:Using dask to schedule tasks for running machine learning models in parallel - pythonSpring Failover redirection failover authentication with option - springC ++ numeric delimiters in Visual Studio - c ++Minimizing journal reports in production - c #python will build a color bar associated with the maximum and minimum number of values - pythonIs there a way to find out which method is called when I click the button - debuggingHow to add ads in the recycler at position 2 in Android? - androidЦель C: возможно ли перехватить все действия пользователя одним классом? - iosКак встроить локальное видео в R Markdown? - rHow to deal with an external service failure in Open-Uri? - ruby | fooobar.comAll Articles