我正在制作一个将 .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/