当你有XML字段时,是否可以使用datacontext或LINQ?我们成功更新了xml字段,但是一旦它在db中,由于上述错误,我们无法更新任何其他字段。我们尝试在Entity上设置(UpdateCheck = UpdateCheck.Never)但这只是意味着xml甚至不会插入。有没有办法绕过这个或我们缺少的选项?
表格如下
CREATE TABLE [Header]
(
ID int NOT NULL IDENTITY (1, 1),
FileName varchar(50) NOT NULL,
XMLData xml NOT NULL,
StatusID int NOT NULL,
TypeID int NOT NULL,
CreatedDate DateTime NOT NULL Default getdate(),
LastUpdatedDate DateTime NOT NULL Default getdate()
) ON [PRIMARY]
实体,当我们尝试添加(UpdateCheck = UpdateCheck.Never)时,它甚至从未插入过xml。
[Table(Name = "Header")]
public class HeaderEntity
{
[Column(IsPrimaryKey = true, IsDbGenerated = true)]
public int ID { get; set; }
[Column]
public String FileName { get; set; }
[Column]
public XDocument XMLData { get; set; }
[Column]
public int StatusID { get; set; }
[Column]
public int TypeID { get; set; }
[Column]
public DateTime LastUpdatedDate { get; set; }
}
此方法有效,但xmldata为空,此方法将其添加。
public void UploadHeaderXML(HeaderEntity HeaderEntityNew)
{
String ConnectionString = ConfigurationManager.ConnectionStrings["DB"].ConnectionString;
var dataContext = new DataContext(new SqlConnection(ConnectionString));
HeaderEntity HeaderEntitytoUpdate = dataContext.GetTable<HeaderEntity>().Single(p => p.ID == HeaderEntityNew.ID);
HeaderEntitytoUpdate.XMLData = HeaderEntityNew.XMLData;
dataContext.SubmitChanges();
}
此方法将错误Linq提供给SQL错误SQL不会比较Xml。
public void UpdateAudit(Int32 ID, Int32 auditID)
{
String ConnectionString = ConfigurationManager.ConnectionStrings["DB"].ConnectionString;
var dataContext = new DataContext(new SqlConnection(ConnectionString));
HeaderEntity HeaderEntitytoUpdate = dataContext.GetTable<HeaderEntity>().Single(p => p.ID == ID);
HeaderEntitytoUpdate.StatusID = auditID;
dataContext.SubmitChanges();
}
答案 0 :(得分:0)
更改更新以更新xml工作。如果有一个更整洁的解决方案,我会接受这个答案。
public void UpdateAudit(Int32 rpaID, Int32 auditID)
{
String ConnectionString = ConfigurationManager.ConnectionStrings["RPADB"].ConnectionString;
var dataContext = new DataContext(new SqlConnection(ConnectionString));
RPAHeaderEntity RPAHeaderEntitytoUpdate = dataContext.GetTable<RPAHeaderEntity>().Single(p => p.RPAID == rpaID);
RPAHeaderEntitytoUpdate.RPAStatusID = auditID;
RPAHeaderEntitytoUpdate.XMLData = new XDocument(RPAHeaderEntitytoUpdate.XMLData);**
dataContext.SubmitChanges();
}