This question is locked. New answers and comments are not allowed.
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
sitefinitysteve
asked on 22 Jan 2010, 11:56 PM
Whats the best way to check if an object already exists in the database? If a user refreshes my form it tries to re-insert the same object back into my table and I get an exception...
Is there a best practice for that?
Is there a best practice for that?
5 Answers, 1 is accepted
0
Hello Steve,
I am afraid you will have to execute a query to determine if an object with particular ID already exists. You can use the FirstOrDefault() method:
The method returns null if the object is not found. Hope that helps.
Greetings,
Alexander
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
I am afraid you will have to execute a query to determine if an object with particular ID already exists. You can use the FirstOrDefault() method:
Customer c = scope.Extent<Customer>().FirstOrDefault(x => x.CustomerID ==
"ALFKI"
);
Greetings,
Alexander
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
answered on 25 Jan 2010, 03:41 PM
Can you check based on an entire object as well?...so not just the ID col, but like an object.Equals()?
0
Hello Steve,
Once you have retrieved the object with the query mentioned in the previous post you can compare it manually to the other object property by property or by implementing a Comparer class that can do this for you.
Kind regards,
Alexander
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Once you have retrieved the object with the query mentioned in the previous post you can compare it manually to the other object property by property or by implementing a Comparer class that can do this for you.
Kind regards,
Alexander
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
answered on 25 Jan 2010, 05:53 PM
Darn, okay thanks :)
Can you put in a feature request for some sort of IfExists(object) support?
Can you put in a feature request for some sort of IfExists(object) support?
0
Hi Steve,
Sure, we will add this feature to our TODO list.
Unfortunately I cannot give you an exact time frame for when it will be implemented at the moment.
Greetings,
Jordan
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Sure, we will add this feature to our TODO list.
Unfortunately I cannot give you an exact time frame for when it will be implemented at the moment.
Greetings,
Jordan
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.