开发者

Linq To Sql Entity Updated from Trigger

I have a Table called Address. I have a Trigg开发者_开发技巧er 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜