SubSonic 不会使用 ActiveRecord 保存更新的记录?
我有一些独特的数据库结构,但我认为我尝试执行的查询并不太不寻常。
基本上,我创建了一个新记录。然后,我保存该记录,更新一些 XML,然后使用新的 XML 更新记录。我遇到的问题是第二次保存没有执行任何操作。
var applicant = new Applicant();
applicant.XmlData = "";
applicant.Save(); //save once and initiate the record
data.RecordRID = applicant.ApplicantRID;
applicant.XmlData = data.SerializeToXml();
var c=applicant.GetDirtyColumns().Count; //this returns a count of 0
applicant.Save(); //save twice to populate RecordRID
另外,作为参考,生成的 XmlData
属性如下所示:
public string XmlData
{
get { return _XmlData; }
set
{
if(_XmlData!=value){
_XmlData=value;
var col=tbl.Columns.SingleOrDefault(x=>x.Name=="XmlData");
if(col!=null){
if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){ //_isLoaded is never set to true for either saves
_dirtyColumns.Add(col);
}
}
OnChanged();
}
}
}
那么..有什么问题吗?我是否需要运行查询并从数据库获取对象然后更新它?或者我错过了什么?
注意:我必须保存两次,因为 ApplicantRID 是唯一的主键。所以我必须插入一条记录才能知道它是什么
I have a bit of a unique database structure but the query I'm attempting to do isn't too out of the ordinary, I think.
Basically, I create a new record. Then, I save this record, then I update a bit of XML and then update the record with the new XML. I'm having problems in that the second save doesn't do anything.
var applicant = new Applicant();
applicant.XmlData = "";
applicant.Save(); //save once and initiate the record
data.RecordRID = applicant.ApplicantRID;
applicant.XmlData = data.SerializeToXml();
var c=applicant.GetDirtyColumns().Count; //this returns a count of 0
applicant.Save(); //save twice to populate RecordRID
Also, for reference, the XmlData
property generated looks like this:
public string XmlData
{
get { return _XmlData; }
set
{
if(_XmlData!=value){
_XmlData=value;
var col=tbl.Columns.SingleOrDefault(x=>x.Name=="XmlData");
if(col!=null){
if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){ //_isLoaded is never set to true for either saves
_dirtyColumns.Add(col);
}
}
OnChanged();
}
}
}
So.. What is the problem? Do I need to run a query and get the object from the database and then update it? or am I missing something?
Note: I have to save this twice because the ApplicantRID is a unique primary key. So I have to insert a record before I can know what it is
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终修改了 SubSonic 的 T4 模板来解决这个问题。
在 ActiveRecord.tt 中,函数
void Add(IDataProvider)
下的第 466 行附近:我没有注意到此更改有任何奇怪之处,而且它似乎是一个错误,它并不存在于其中。 。
I ended up modifying the T4 templates of SubSonic to fix this.
In ActiveRecord.tt around line 466 under the function
void Add(IDataProvider)
:I have not noticed any weirdness from this change, and it seems like a bug that it wasn't already in there as it is.