Linq To Sql Entity Updated from Trigger
Posted
by James Helms
on Stack Overflow
See other posts from Stack Overflow
or by James Helms
Published on 2010-05-02T01:06:05Z
Indexed on
2010/05/02
1:17 UTC
Read the original article
Hit count: 197
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?
© Stack Overflow or respective owner