JSON を XML に変換し、データをテーブルに挿入するこのコードがあります。ただし、xml データが格納されるテーブル列は null です。入れていません。
[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を挿入していない理由は何ですか?