ianvink wrote:
Walaa wrote:
A single entity is fetched using the PK value.
Otherwise your fetching an EntityCollection, even if you need one entity.
If I have a unique index on a column, say the Email of the "Customer" table which is not the PK, there doesn't seem to be a way to single-entity Fetch with the adapter based on that. Is that correct.
If there was that would be helpful too.
Linq is about sets, enumerating sets and obtain data from these sets. So single entities are always fetched by enumerating the overall set with a where filter etc. (inside the db).
So you can use FirstOrDefault on LinqMetaData.Customer with a filter on Email, which will result in a single entity, as just 1 entity matches the query. That it is placed inside a collection internally is not that important, you won't see the collection, only the entity:
var customer = new LinqMetaData(adapter).Customer.FirstOrDefault(c=>c.Email==someEmail);