我有一个包装类,用于从 dbml 的部分类之一中的属性获取和设置代码。使用包装器的原因是为了进行专门的获取,它预先格式化值。包装器如下所示(注意:这不是实际的代码,但代表了除格式之外的所有内容):
partial class Class1
{
public string PropertyFormatted
{
get
{
var ret = Property.Substring(1);
return ret;
}
set { Property = value; }
}
}
该包装器使用 Bind() 绑定在编辑页面的表单视图中。由于某种原因,包装器的值在更新时被设置两次,第二次该值被重新分配其原始值(导致该属性最终保持不变)。但是,当包装器替换为属性本身时,保存到数据库就没有问题了。
有什么想法可能是什么原因造成的吗?
I have a wrapper class that is meant to get and set code from a property in one of my dbml's partial classes. The reason for the wrapper is for a specialized get, which pre-formats the value. Here's what the wrapper looks like (NOTE: this is not the actual code, but represents everything but the formatting accurately):
partial class Class1
{
public string PropertyFormatted
{
get
{
var ret = Property.Substring(1);
return ret;
}
set { Property = value; }
}
}
This wrapper is bound using Bind() in a formview for the edit page. For some reason, the wrapper's value is set twice on update and the second time through the value is re-assigned its original value (causing the property to remain, ultimately, unchanged). However, when the wrapper is replaced with the property itself, there is no problem with saving to the database.
Any ideas what may be the cause of this?
dbContext 应通过此方法自动检测更改:
"="">http://msdn.microsoft.com/en-us/library/system.data.entity.infrastruct.dbchangetracker.detectchanges(v=vs.103).aspx
您可能不经意间禁用自动检测更改或类似的东西。尝试手动调用该方法,看看是否有影响。
祝你好运!
The dbContext should be automatically detecting changes via this method:
http://msdn.microsoft.com/en-us/library/system.data.entity.infrastructure.dbchangetracker.detectchanges(v=vs.103).aspx
You may have inadvertently disable auto detect changes or something of the like. Try manually calling the method and see if that makes a difference.
Good luck!