I have a short question. Im my current project I’m using LINQ-to-SQl. That is the best way to determine if table has record with specific ID?
Thanks in advance.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you just need to know if it exists, then perhaps:
If you want the row (or
nullif it doesn’t exist), then:actually, in .NET 3.5 there is arguably a benefit to using:
but this is fixed in 4.0 and both work the same. The difference is that in 3.5SP,
FirstOrDefault(predicate)doesn’t check the identity-manager, so it would hit the db even if it already knows about the row you asked for (because it has it in-memory).