I noticed that when I work with a new entity and invoke the related collection of entities, the runtime always tries to fetch data from the database.
For example, imagine that we have Agency and Location tables (1:m). This code
var agencyEntity = new AgencyEntity();
agencyEntity.Locations.Add(new LocationEntity());
queries database for Locations:
exec sp_executesql N'SELECT [Test].[dbo].[Location].[Id], [Test].[dbo].[Location].[AgencyId], [Test].[dbo].[Location].[Street] ... FROM [Test].[dbo].[Location] WHERE ( ( [Test].[dbo].[Location].[AgencyId] = @AgencyId1))',N'@AgencyId1 int',@AgencyId1=0
and this operation is redundant, because AgencyEntity is new.
I've found a workaround:
var agencyEntity = new AgencyEntity {AlreadyFetchedLocations = true};
agencyEntity.Locations.Add(new LocationEntity());
But it seems unnatural to use it in whole project. Do I have an alternative?
PS. I use the last version of LLBLGen (06-Apr-2009).
Thank you.