c# - 为 C# .NET 编写 typeof(Xml) 的正确方法是什么?

标签 c# .net xml types

我正在制作一个将 .NET 类型映射到 Sql Server 类型的字典。我正在使用MSDN's "SQL Server Data Type Mappings" page向我展示什么是正确的转换。表底部显示 .NET 框架类型是 Xml,所以我写道:

{typeof (Xml), "xml"}

作为字典的键值对。但 Resharper 的 Xml 为红色,并表示无法解析该符号。 typeof(Xml) 的正确说法是什么?这就是我的字典的其余部分的样子,它没有任何问题:

private static readonly Dictionary<Type, string> SqlServerMap = new Dictionary<Type, string>
{
    {typeof (Int64), "bigint"},
    {typeof (Boolean), "bit"},
    {typeof (Byte[]), "binary"},
    {typeof (Double), "float"},
    {typeof (Int32), "int"},
    {typeof (Decimal), "decimal"},
    {typeof (Single), "real"},
    {typeof (Int16), "smallint"},
    {typeof (DateTime), "date"},
    {typeof (TimeSpan), "time"},
    {typeof (String), "nvarchar"},
    {typeof (Guid), "uniqueidentifier"},
    {typeof (Byte), "tinyint"},
    {typeof (Xml), "xml"}
};

最佳答案

要为 XML 进行从 .NET 到 SQL 的映射,您似乎需要使用 SqlXml 类型,因为没有直接的 Xml 类型。

这里有详细的implementation example from MSDN .

当涉及到映射时,如果需要,您可以使用 XDocument 等内容,然后手动将其交换到 SqlXml 以实现持久性?

关于c# - 为 C# .NET 编写 typeof(Xml) 的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31593523/

相关文章:

c# - 如何在更改值时更改彼此的文本框(MVVM)

html - 在输入时自动关闭正确的 XML/HTML 标签 </

xml - 强制 Spring Web 服务将 xsd 命名空间添加到响应中

c# - 如何在 Xamarin C# 中更改字体/颜色/大小

c# - 使用 Visual Studio 2010 创建 XML 架构并从中自动生成可序列化类

c# - 是否可以仅为 MVC/Controller Action 请求执行 IHttpModule?

c# - 需要使用返回类型字符串数组方法

.net - 尊重结构的正则表达式字符组

c# - Surface 2 RT 上的 Windows PDF API 渲染错误

php - 在 PHP 中更改 XML 节点元素值并保存文件