For example I am searching for a specific persons ID and I want to store that ID to a local variable or instance variable. How do I retrieve Query results and stores them in a int Variable with LINQ to SQL? Assuming we have this query
from user in dbo.DoctorsName
where doctorsName = "Foo Bar"
select DOC_ID;
LINQ to SQL translates the queries you write into equivalent SQL queries and sends them to the server for processing. More specifically, your application uses the LINQ to SQL API to request query execution. The LINQ to SQL provider then transforms the query into SQL text and delegates execution to the ADO provider.
LINQ to SQL was the first object-relational mapping technology released by Microsoft. It works well in basic scenarios and continues to be supported in Visual Studio, but it's no longer under active development.
You can get same generated SQL query manually by calling ToString: string sql = committeeMember. ToString();
You can use FirstOrDefault()
like this:
var results = from user in dbo.DoctorsName
where user.doctorsName == "Foo Bar"
select user;
string personName = results.FirstOrDefault().Name;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With