我有这段代码将 JSON 转换为 XML,然后将数据插入到表中。但是xml数据所在的表列是空的。它没有插入。
[HttpPost]
public void SaveData(Newtonsoft.Json.Linq.JObject data)
{
string agency = data.Root.ToString();
XmlDocument doc = JsonConvert.DeserializeXmlNode(agency, "agency");
Newtonsoft.Json.Linq.JToken[] ArrAgency = data.Root.ToArray();
dynamic DeserializedData = JsonConvert.DeserializeObject(data.ToString());
tblAgencyQuery tblAgencyQuery = new tblAgencyQuery();
tblAgencyQuery.QueryID = Guid.NewGuid();
tblAgencyQuery.QueryText = doc;
tblAgencyQuery.AgencyID = DeserializedData.agencyID;
tblAgencyQuery.CreatedDate = DateTime.UtcNow;
_ContextProvider.Context.tblAgencyQuery.Add(tblAgencyQuery);
_ContextProvider.Context.Entry(tblAgencyQuery).State = System.Data.EntityState.Added;
_ContextProvider.Context.SaveChanges();
}
我的模型
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;
namespace AgencyUpdate.Models
{
public class tblAgencyQuery
{
[Key]
public Guid QueryID { get; set; }
[NotMapped]
public System.Xml.XmlDocument QueryText { get; set; }
public int AgencyID { get; set; }
public DateTime CreatedDate { get; set; }
}
}
表的 SQL 脚本
USE [GenesisOnline]
GO
/****** Object: Table [dbo].[tblAgencyQuery] Script Date: 20/09/2013 11:17:34 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblAgencyQuery](
[QueryID] [uniqueidentifier] NOT NULL,
[QueryText] [xml] NULL,
[AgencyID] [int] NULL,
[CreatedDate] [datetime] NULL,
CONSTRAINT [PK_tblAgencyQuery] PRIMARY KEY CLUSTERED
(
[QueryID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON
, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE [dbo].[tblAgencyQuery] ADD CONSTRAINT [DF_tblAgencyQuery_CreatedDate] DEFAULT (getutcdate()) FOR [CreatedDate]
GO
知道为什么这不插入xml吗?