I've looked back at the design documents of this feature but what I mentioned above isn't entirely correct: when passing an entity collection to the DataScope.Attach() method, it is added to the internal context as well as its contents, what I mentioned above is true for when you call TrackQuery: the resulting entity collection returned by a query isn't tracked.
We setup a test to try to reproduce what you mentioned, but we can't, it works as you expected:
[Test]
public void InsertThroughCollectionTest()
{
var scope = new UpdateInsertDataScope(10254);
var orderDetails = new EntityCollection<OrderDetailsEntity>();
scope.Add(orderDetails);
// add new entity to collection, it should be picked up now
var newOrderDetail = new OrderDetailsEntity();
newOrderDetail.ProductId = 1;
newOrderDetail.OrderId = 10254;
newOrderDetail.Quantity = (short)10;
newOrderDetail.Discount = 0.0f;
newOrderDetail.UnitPrice = 10.2M;
orderDetails.Add(newOrderDetail);
UnitOfWork2 uow = null;
Func<IUnitOfWorkCore, bool> commitFunc = a => { uow = (UnitOfWork2)a; return true; };
scope.CommitChanges(commitFunc);
uow.ConstructSaveProcessQueues();
var insertQueue = uow.GetInsertQueue();
var updateQueue = uow.GetUpdateQueue();
Assert.AreEqual(1, insertQueue.Count);
Assert.AreEqual(0, updateQueue.Count);
Assert.AreEqual(newOrderDetail, insertQueue.First().Entity);
}
// the Add method in the DataScope derived class:
public void Add(IEntityCollection2 entityCollection)
{
this.Attach(entityCollection);
}
This test succeeds correctly, as expected. We add an empty collection to the scope, then add an entity to the collection and it's picked up by the scope as expected.
Attaching a filled collection also works:
[Test]
public void UpdateThroughCollectionTest()
{
var scope = new UpdateDataScope("USA");
Assert.IsTrue(scope.FetchData());
var customers = scope.Customers;
customers[0].City += "Foo";
UnitOfWork2 uow = null;
Func<IUnitOfWorkCore, bool> commitFunc = a => { uow = (UnitOfWork2)a; return true; };
scope.CommitChanges(commitFunc);
uow.ConstructSaveProcessQueues();
var insertQueue = uow.GetInsertQueue();
var updateQueue = uow.GetUpdateQueue();
Assert.AreEqual(0, insertQueue.Count);
Assert.AreEqual(1, updateQueue.Count);
Assert.AreEqual(customers[0], updateQueue.First().Entity);
}
// scope:
public class UpdateDataScope : DataScope
{
#region Class Member Declarations
private string _country;
private EntityCollection<CustomerEntity> _customers;
#endregion
public UpdateDataScope(string country)
{
_country = country;
}
protected override bool FetchDataImpl(params object[] fetchMethodParameters)
{
using(var adapter = new DataAccessAdapter())
{
_customers = new EntityCollection<CustomerEntity>();
adapter.FetchEntityCollection(_customers, new RelationPredicateBucket(CustomerFields.Country==_country));
this.Attach(_customers);
}
return _customers.Count>0;
}
public void Add(IEntityCollection2 entityCollection)
{
this.Attach(entityCollection);
}
public EntityCollection<CustomerEntity> Customers
{
get { return _customers; }
}
}
Test succeeds as well. Now, if you use the TrackQuery to attach that entitycollection, then it's by design that it isn't added. However if you're using the above construct, then we're looking at a bug to fix instead.
Could you give us more information what exactly you're doing in this particular case so we can try to replicate it here and see what needs changing?