Hello people!
I wonder if there are collections that executes SQL queries against the
DB instead of using the in-memory collection... Let me show some examples...
class Address {
// This class might have more properties...
public string AddressLine { get; }
}
class Person {
public IEnumerable<Address> Addresses { get; }
public void Add(Address address)
{
// ...
}
public void Remove(Address address)
{
// ...
}
}
// Example SQL...
// SELECT * FROM [Persons] WHERE [Id] = 1;
Person p = personRepository.First(p => p.Id == 1);
// SELECT COUNT(*) FROM [Addresses_Persons] WHERE [Person] = 1;
int numberOfAddresses = p.Addresses.Count();
// SELECT * FROM [Addresses_Persons] WHERE [Person] = 1 AND [Id] = 2;
Address address = p.Addresses.First(a => a.Id == 2);
This might be ineffective on small collections, I don't really know. But
when it comes to complete DDD Aggregate root entities this might prove
itself VERY effective if you don't want the actual data, just something
about the data. Say you get queries like this.
// First get the root entity.
RootEntity rootEntity = repository.First(x => x.Id == 1);
// Get some other entity in a collection.
SubEntity subEntity = rootEntity.SubEntities.First(x => x.Id == 50);
// Get a subset of the entities within this subEntity.
var subSubEntities = subEntity.ACollection.Where(x => x.IsRead);
// All of this would generate something like this...
SELECT [SubSubEntities].* FROM [SubSubEntities]
LEFT JOIN [SubEntities] ON [SubEntities].[Id] = [SubSubEntities].[Parent]
WHERE [SubSubEntities].[IsRead] = 1 AND [SubEntities].[Id] = 50
AND [SubEntities].[Parent] = 1;
or maybe two queries, anyway, the important part is NOT to fully load
everything like lazy-load does now, but to load the data I need.
Is this possible somehow and is it possible it might already be created?
Thanks!
// Kim Johansson
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---