LLBLGen Framework 5.8.2, Adapter with SQL Server and AdventureWorksLT
This test fails as the detail entity, of which there is one, gets into the SalesOrderHeader.SalesOrderDetails twice, no doubt due to the slightly odd prefetch construct. In this scenario the key for the detail is given, so the detail is the root entity in the prefetch, but all the details under the header are required. Having 2 elements in the SalesOrderHeader.SalesOrderDetails collection seems wrong to me, but maybe this is by design?
[Test]
public void SameInPrefetch()
{
var salesOrderHeader = new SalesOrderHeaderEntity
{
SalesOrderId = 1,
OrderDate = DateTime.Today,
DueDate = DateTime.Today,
CustomerId = 1,
ShipMethod = "",
};
salesOrderHeader.SalesOrderDetails.Add(new SalesOrderDetailEntity
{
OrderQty = 1,
UnitPrice = 1,
ProductId = 680,
});
var daa = new DataAccessAdapter("Server=tcp:localhost;Database=AdventureWorksLT2019;Integrated Security=SSPI;");
daa.SaveEntity(salesOrderHeader, true, true);
var meta = new LinqMetaData(daa);
var detail = (from d in meta.SalesOrderDetail
where d.Rowguid == salesOrderHeader.SalesOrderDetails[0].Rowguid
select d).WithPath(de => de.Prefetch<SalesOrderHeaderEntity>(dp => dp.SalesOrderHeader)
.SubPath(headerP => headerP.Prefetch(h => h.SalesOrderDetails))).Single();
Assert.AreEqual(1, detail.SalesOrderHeader.SalesOrderDetails.Count);
}