Hi,
LLBLGen 5.8.1 with Adapter
I want to use the DataScope functionality and have the most efficient network traffic when persisting changes from the client to the server. I have this example where I expect to just get 1 entity in the UnitOfWork, but the FastSerializer is serializing a total of 4 objects, even though only 1 is new/dirty. I could create my own unitOfWork by taking the passed in IUnitOfWorkCore and copying just those entities which are IsNew/IsDirty/IsDeleted, but is there a better, more efficient way?
This is from the AdventureWorksLT2019 database.
class Program
{
static void Main(string[] args)
{
var meta = new LinqMetaData(new DataAccessAdapter("data source = localhost; initial catalog = AdventureWorksLT2019;Integrated Security=SSPI;"));
var o = (from oh in meta.SalesOrderHeader
where oh.SalesOrderId == 71774
select oh).WithPath(op => op.Prefetch(or => or.SalesOrderDetails)).Single();
var scope = new MyDataScope();
scope.Attach(o);
o.SalesOrderDetails.Add(new SalesOrderDetailEntity());
scope.CommitChangesAsync(CommitFunc, new CancellationToken());
}
static Task<bool> CommitFunc(IUnitOfWorkCore arg1, CancellationToken arg2)
{
var uow = (UnitOfWork2) arg1;
new FastSerializer().Serialize(uow);
if (SalesOrderHeaderEntity.EntitiesSerialized != 0 || SalesOrderDetailEntity.EntitiesSerialized != 1)
{
throw new Exception("too many entities in UoW");
}
return Task.FromResult(false);
}
class MyDataScope : DataScope
{
internal void Attach(IEntityCore e)
{
base.Attach(e);
}
}
}
And in the 2 entities I track the serialization with simply:
public partial class SalesOrderHeaderEntity
{
public static int EntitiesSerialized;
protected override void SerializeOwnedData(SerializationWriter writer, object context)
{
base.SerializeOwnedData(writer, context);
EntitiesSerialized++;
}
}
And the same for :
public partial class SalesOrderDetailEntity
{
public static int EntitiesSerialized;
protected override void SerializeOwnedData(SerializationWriter writer, object context)
{
base.SerializeOwnedData(writer, context);
EntitiesSerialized++;
}
}
Thanks,