开发者

Linq to SQL error SQL does not compare Xml?

is it possible to use a datacontext or LINQ when you have an XML field? we succeed in updating the xml field in but once it is in the db, we cannot update any other fields due to the above error. we tried setting the (UpdateCheck=UpdateCheck.Never) on the Entity but this just means the xml won't even insert. Are there any ways around this or options we are missing?

the table is the below

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]

the entity, when we tried adding (UpdateCheck=UpdateCheck.Never) it never even inserted the 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; }
}

this method works, but the xmldata is empty and this method adds it.

    public void UploadHeaderXML(HeaderEntity HeaderEntityNew)
    {
        String ConnectionString = ConfigurationManager.ConnectionStrings["DB"].ConnectionString;
        var dataContext = new DataContext(new SqlConnection(ConnectionString));

        HeaderEntity HeaderEntit开发者_Python百科ytoUpdate = dataContext.GetTable<HeaderEntity>().Single(p => p.ID == HeaderEntityNew.ID);
        HeaderEntitytoUpdate.XMLData = HeaderEntityNew.XMLData;

        dataContext.SubmitChanges();
    }

This method gives the error Linq to SQL error SQL does not compare 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();
    }


Changing the Update to update the xml worked. If there is a tidier solution though, i would accept that as an answer.

    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();
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜