I'm writing a database test against a repository that uses L2S. In my database I have a Manifest
entity and an AllocatedTransaction
entity. The AllocatedTransaction entity has a foreign key to the Manifest's id. The DDL looks something like this:
Manifest:
Id - int - identity
AllocateTransaction:
Id - int - identity
Quantity - int
ManifestId - FK to Manifest
In my test, I'm checking to see if AllocatedTransactions are coming back with the Manifest. The test looks like this:
[TestMethod]
public void FindByIdTest()
{
using (data.EZTracDataContext dataContext = new data.EZTracDataContext())
{
using (new TransactionScope())
{
data.Manifest manifest = _testDataProvider.AddManifest(dataContext);
data.AllocatedTransaction allocatedTransaction = _testDataProvider.AddEligibilityAllocated(dataContext, 5, manifest.Id);
ManifestRepository repository = CreateRepository(dataContext);
var actual = repository.FindById(manifest.Id).AllocatedTransactions;
var expected = new[] { new domain.AllocatedTransaction(allocatedTransaction.Id, 5, manifest.Id) }.ToList();
CollectionAssertAreEqual(actual, expected);
}
}
}
The _testDataProvider
just adds records to the database using the passed in dataContext
. The FindById
method looks like this:
public domain.Manifest FindById(int id)
{
var persistedManifest = GetPersistedManifest(id);
var requestedManifest = GetDomainManifestFromData(persistedManifest);
return requestedManifest;
}
private Manifest GetPersistedManifest(int manifestId)
{
return (from manifests in DataContext.Manifests
where manifests.Id == manifestId
select manifests).FirstOrDefault();
}
My problem is the Manifest entity coming back from the DataContext does not have the AllocateTransaction associated to it. The strange thing is pre-existing Manifests do come back with their AllocatedTransactions attached. Could using the same DataContext object for inserting the records and retrieving the records be causing this? Is this a bug with L2S?