c# - Linq to SQL datacontext not updating for foreign key relationships -


I am writing a database test against a repository that uses L2S in my database with a manifest unit and a allocated tradespeople unit. The assigned transaction unit has a foreign key for the ID of the manifest: DDL looks like this:

  manifest : id - int - identifying allocateTransaction: id - int - identifying quantity - integer ManifestId - FK To appear,  

In my trial, I see whether allocated transactions are coming back with the manifest or not. The test looks like this: [New TransactionScope (using the new data.EZTracDataContext ()) using {{Data.EZTracDataContext] {Test} using the public Zero FindByIdTest () {} ) {Data. Manifest manifest = _testDataProvider.AddManifest (datacontax); Data Approved transaction Edit Allocated transactions = _testDataProvider.AddableabilityAllocated (dataContext, 5, manifest.Id); ManifestRepository Repository = Create Repository (Datacontax); Var real = repository FindbyID (Manifest.Id). Allocated Transaction; Var is expected = new [] {new domain. Allocated Transaction (Allocated Transaction .ID, 5, Manifest.id)} .Oolist (); CollectionArtArequal (actual, expected); }}

_testDataProvider Adds a record of the database passed in the dataContext in the bus. The FindById method looks like this:

  public domain. MANIFEST FindById (int id) {var persistedManifest = GetPersistedManifest (id); Var requestManifest = GetDomainManifestFromData (persistedManifest); Refund requested environment; } Private manifest GetPersistedManifest (int manifestId) {Return (from Manifest in DataContext, in which select manifest ID == Manifest Manifest). FirstOver Default (); }  

My problem is that the return entity from Datacintex does not have AllocateTransaction associated with it. The strange thing is that the already existing manifestations do your allocated transactions are enclosed so that they can use the same data contact object to include the records and retrieve the records. Due to this can it be? Is it a bug with L2S?

If I understand your question, then this is what you are doing to do this Trying

using (new TransactionScope ()) {manifest manifest = new manifest {allocatedTransactions.Add (New AllocatedTransaction {volume = 5}} ;? DataContext.Manifests.InsertOnSubmit (Manifested); DataContext.SubmitChanges (); appear newManifest = DataContext.Manifests.Where (a => a.ID == manifest.ID) .SingleOrDefault (); Assert.AreEqual (manifest.AllocatedTransactions.First () Quantity, newManifest.AllocatedTransactions first () quantity);}}

You also manually appear with AllocatedTransaction entities connected do not need to be retrieved just as I did with newManifest object and all related AllocatedTransaction

Update:

It seems that you are trying to engage in the wrong direction. You have to attach AllocatedTransaction to appear, not the other way around the need:

  manifest manifest = DataContext.Manifests.Single (a => gt; .id == 27); All Transactions All Trans = DataContacts Recommended Transaction Single (A => AID == 53); Manifest.AllocatedTransactions.Add (allTrans); DataContext.SubmitChanges ();  

It believes that both the manifest and allotted transaction records are present. I highly recommend that you do not prepare the ManifestID field in the allocated Transaction object. If you have shown it above, like you add it, then the LINQ engine will automatically resolve the foreign key value and update it. If you set the price ahead of time, it may turn off ChangeSet and assume that you are trying to add a new record instead of attaching an existing one.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -