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

本文关键字:方法 是什么 Xml net 编写 typeof | 更新日期: 2023-09-27 18:04:13

我正在制作一个字典,将。net类型映射到Sql Server类型。我正在使用MSDN的"SQL Server数据类型映射"页面向我展示正确的转换是什么。在表格底部,它说。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"}
};

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

要从。net映射到SQL for XML,似乎需要使用SqlXml类型,因为没有直接的XML类型。

下面是来自MSDN的详细实现示例。

说到映射,你可以使用像XDocument之类的东西,如果你想,然后手动交换到SqlXml持久化可能?