I can not believe this. Intellisensing ItemCollection gives a single item with id = 0 after SaveChanges.
Dim ItemCollection = From d In action.Parameter Select New STOCK_TYPE With { .Code = d.ParamValue.<Code>.Value, .GeneralUseID = d.ParamValue.<GeneralUse>.Value, } GtexCtx.STOCK_TYPE.AddObject( ItemCollection.FirstOrDefault) GtexCtx.SaveChanges()
No matter what I do. After 8 hours, including deleting my model, building and rebuilding 35 times, experimenting and editing XML EDMX, it is now almost ready to delete my entire SQL Server database. On the 36th comp, this crazy solution worked
Dim abc = ItemCollection.FirstOrDefault GtexCtx.STOCK_TYPE.AddObject(abc) GtexCtx.SaveChanges()
abc.ID yield 41 (identity required)
EDIT: Here is a simple code to think through AddObject and still get the id
Dim listOfST As List(Of STOCK_TYPE) = ItemCollection.ToList() For Each q As STOCK_TYPE In listOfST GtexCtx.STOCK_TYPE.AddObject(q) Next GtexCtx.SaveChanges() ...more code for inter-relationship tables
Try entering Intellisence listOfST after SaveChanges and you will find the updated identifier. Maybe thereβs a better way, but the concept is there
Fun Chiat Chan Mar 31 '12 at 17:58 2012-03-31 17:58
source share