开发者

.NET Entity Framework not updating every column when an entity is persisted

I have an entity. I'm mostly manipulating this entity via a databound form, although I did trap the PreSave event in the ObjectModel class to inject a few audits. 99% of this works perfectly fine, including the "DateModified" audit column that I'm using.

But there are two audits that are also put onto the model object- "ModifiedBy" and "Usable" (a true/false value based off a business rule). I can set both of those successfully on the entity. I can confirm that they propagate all the way down to the PreSave event handler. I can confirm that no subsequent saves are blowing out those values or anything.

But it doesn't work. Neither of those columns actually get saved. The DateModified column, on the other hand, does get updated, every time.

For Each m In mattersToValidate.Where(Function(mm) Not mm Is Nothing)
        m.DateModified = Now() 'works
        m.CSCRecentAdd = False 'works
        Debug.Assert(m.ModifiedBy = "DOMAIN\USER") 'My user name- this is true (the value actually comes from a databound control, but this Assert passes, despite the value not reaching the DB).
        m.ValidMatter = m.Validation 'doesn't work
        If m.LawSection.LawSectionName = CLAIMABLE Then
            m.ClaimNumber = m.MatterID 'works
        Else
            m.ClaimNumber = Nothing
        End If
    Next

I should add that the entity points directly at the database table, and is not g开发者_JS百科oing through a view or SP or anything else.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜