【发布时间】:2009-07-22 20:59:35
【问题描述】:
我想在不先从数据库加载实体的情况下更新实体。
我已经完成了这一点,但只是通过了解所有实体属性然后使用“attachto”方法。
我的问题是我不希望我的应用程序需要记住所有属性。示例:
Dim customerEntitiy As New shopper
customerEntitiy.shopper_id = CustomerData.CustomerID
customerEntitiy.market_code = CustomerData.MarketSector
customerEntitiy.email = CustomerData.Email
customerEntitiy.modified = DateTime.Now
context.AttachTo("shopper", customerEntitiy)
context.SaveChanges()
该实体上还有一个“已创建”字段。我不想通过我的 n 层应用程序一直传递这个“创建”日期。保存到数据库时如何“不更新”该字段?谢谢! 保罗
【问题讨论】:
-
虽然可以做你想做的事,但不推荐这样做,因为实体可能没有直接链接到表。例如,我使用与视图关联的实体,并使用过程进行更新。这种方法会产生非常不利的影响...
标签: .net vb.net entity-framework ado.net