I'm currently planning on switching my "manual query-writing" code to a nice SQL framework, so I can leave the queries or sql things to the framework, instead of writing the queries myself.
Now I'm wondering how I can get a single record from my table in Entity Framework 4?
I've primarily used SQL like SELECT * FROM {0} WHERE Id = {1}
. That doesn't work in EF4, as far as I'm concerned.
Is there a way I can select a single ID-Based record from my Context?
Something like:
public Address GetAddress(int addressId)
{
var result = from Context.Addresses where Address.Id = addressId;
Address adr = result as Address;
return Address;
}
Thank you!
Using Select.Single and SingleOrDefault.: var c = from c in db. table where c.id== id select new { Name = c.Name, }; var query = (from c in db. table where c.id== "Classic id" select new { c.
In Entity Framework Core we can select specific columns by using either anonymous types or DTOs.
var address = Context.Addresses.First(a => a.Id == addressId);
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