Linq To Sql Entity Updated from Trigger
- by James Helms
I have a Table called Address. I have a Trigger for insert on that table that does some spacial calculations on the address that determines what neighborhood boundaries it is in.
address = new Address
{
Street = this.Street,
City = this.City,
State = this.State,
ZipCode = this.ZipCode,
latitude = this.Latitude,
longitude = this.Longitude,
YearBuilt = this.YearBuilt,
LotSize = this.LotSize,
FinishedSize = this.FinishedSize,
Bedrooms = this.Bedrooms,
Bathrooms = this.Bathrooms,
UseCode = this.UseCode,
HOA = this.HOA,
UpdateDate = DateTime.Now
};
db.AddToAddresses(address);
db.SaveChanges();
In the database i can clearly see that the Trigger ran and updated the neighborhoodID in the address table for the row. I tried to just reload that record to get the assigned id like this:
address = (from a in db.Addresses where a.AddressID == address.AddressID select a).First();
In the debugger i can clearly see that the address.AddressID is correct, entity doesn't update in memory.
Is there any work around for this?