Note that there are some explanatory texts on larger screens.

plurals
  1. POLinq->Entities and foreign key table issue
    primarykey
    data
    text
    <p>C# and general programming noobie here.</p> <p>I have two tables. Property and Memo. There can be many Memo's to a single Property. I have, at least I think I do, the format of the object creation done correctly. The issue I do have is the Memo object doesn't save with the Property object. The Property object seems to save just fine.</p> <hr> <p><em>Since I am a stack-noobie, I cannot post images strait into the post, so I've uploaded a couple which show both my Entities Diagram and the Referential Constraint dialogue.</em></p> <p><strong>www.jmtland.com/Pics/Diagram.png</strong></p> <p><strong>www.jmtland.com/Pics/Referential%20Constraint.png</strong></p> <hr> <pre><code> MTDBEntities1 dc = new MTDBEntities1(); Property newProp = new Property(); newProp.Address = t_Address.Text.Trim(); newProp.City = t_City.Text.Trim(); newProp.State = t_State.Text.Trim(); newProp.Zip = t_Zip.Text.ToString(); newProp.PropertyType = cb_PropertyType.Text.Trim(); if (t_SizeMin.Text.Trim().Length != 0) { newProp.SizeMin = Convert.ToInt64(t_SizeMin.Text); } // SizeMin is not required, so it won't be passed to the DB if there is no value. newProp.SizeMax = Convert.ToInt64(t_SizeMax.Text); newProp.SizeMetric = cb_SizeType.Text.Trim(); if (t_PriceMin.Text.Trim().Length != 0) { newProp.PriceMin = Convert.ToDecimal(t_PriceMin.Text); } // PriceMin is not required, so it won't be passed to the DB if there is no value. newProp.PriceMax = Convert.ToDecimal(t_PriceMax.Text); newProp.LeaseType = cb_LeaseType.Text.Trim(); newProp.WebLink = t_WebLink.Text.Trim(); newProp.Deleted = false; newProp.DateDeleted = null; newProp.DateCreated = DateTime.Now; Memo newMemo = new Memo(); newMemo.Memo1 = t_PropertyMemo.Text.Trim(); newMemo.MemoDateCreated = DateTime.Now; newProp.Memos.Add(newMemo); dc.AddToProperties(newProp); dc.SaveChanges(); </code></pre> <p>I've been searching around for a fix for this problem for the last two days on multiple forums. I've followed so many examples that I almost forgot my original code.</p> <p>Sorry for the noobness.</p> <p>Update: I have tried saving the Property Table first, then the Memo table. -Doesn't work either.</p> <p>I have run through the debugger and there seems to be data associated with the Memo object as well as the Property object contains the Memo object in question but it, for some reason, doesn't save at the same time.</p> <p>I've though about a different way around it, where I could save the property, then do a new query to get the PropertID of that new object, then force save the Memo object with the PropertyID returned.</p> <p>The issue I have with that method is that would mean my understanding of the Entity framework wouldn't be correct. I'd probably be able to hack my way around it but if I can't get it to work properly from the beginning, I fear that my later implementation of the same tech will be hindered by my inability to get it right from the get go. I've dabbled in programming before and the one thing I've learned is if you don't learn the basics right the first time, the rest of your experience can be corrupted.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload