views:

59

answers:

1

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?

A: 

I added

db.Refresh(System.Data.Objects.RefreshMode.StoreWins, address);

right before

address = (from a in db.Addresses where a.AddressID == address.AddressID select a).First();

and that fixed my problem.

James Helms
Welcome to Stack Overflow! Great that you solved your problem yourself and share the solution. To follow SO conventions you should also mark your answer as the "accepted" one by clicking the check mark.
Anders Abel