publicvoid UpdateBlogCoinfigLastUpdatedTest() { using (BlogDbContext context =new BlogDbContext()) { var blog =new Blog() { BlogID =0, LastModified = DateTime.Now }; context.BlogConfigs.Attach(blog); var stateEntry = ((IObjectContextAdapter)context).ObjectContext. ObjectStateManager.GetObjectStateEntry(blog); stateEntry.SetModifiedProperty("LastUpdated"); context.SaveChanges(); } }
EF生成的SQL语句如下:
exec sp_executesql N'update [dbo].[blog_Config]set [LastUpdated] = @0where ([BlogID] = @1) ',N'@0 datetime2(7),@1int',@0='2011-04-0614:12:28.2129938',@1=0