Skip to content

Commit a8b185f

Browse files
committed
Map SQLServer xml columns to string properties.
1 parent 29a0b78 commit a8b185f

File tree

6 files changed

+9
-3
lines changed

6 files changed

+9
-3
lines changed

src/Microsoft.EntityFrameworkCore.SqlServer/Storage/Internal/SqlServerTypeMapper.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class SqlServerTypeMapper : RelationalTypeMapper
3636
private readonly RelationalTypeMapping _uniqueidentifier = new RelationalTypeMapping("uniqueidentifier", typeof(Guid));
3737
private readonly RelationalTypeMapping _decimal = new RelationalTypeMapping("decimal(18, 2)", typeof(decimal));
3838
private readonly RelationalTypeMapping _time = new RelationalTypeMapping("time", typeof(TimeSpan));
39+
private readonly RelationalTypeMapping _xml = new RelationalTypeMapping("xml", typeof(string));
3940

4041
private readonly Dictionary<string, RelationalTypeMapping> _simpleNameMappings;
4142
private readonly Dictionary<Type, RelationalTypeMapping> _simpleMappings;
@@ -82,7 +83,8 @@ public SqlServerTypeMapper()
8283
{ "tinyint", _tinyint },
8384
{ "uniqueidentifier", _uniqueidentifier },
8485
{ "varbinary", _varbinary },
85-
{ "varchar", _varchar }
86+
{ "varchar", _varchar },
87+
{ "xml", _xml }
8688
};
8789

8890
_simpleMappings

test/Microsoft.EntityFrameworkCore.SqlServer.Design.FunctionalTests/ReverseEngineering/Expected/AllFluentApi/AllDataTypes.expected

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ namespace E2ETest.Namespace
4646
public byte[] varbinaryMaxColumn { get; set; }
4747
public byte[] timestampColumn { get; set; }
4848
public Guid? uniqueidentifierColumn { get; set; }
49+
public string xmlColumn { get; set; }
4950
public string typeAliasColumn { get; set; }
5051
public byte[] binaryVaryingColumn { get; set; }
5152
public byte[] binaryVarying133Column { get; set; }

test/Microsoft.EntityFrameworkCore.SqlServer.Design.FunctionalTests/ReverseEngineering/Expected/AllFluentApi/SqlServerReverseEngineerTestE2EContext.expected

+2
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ namespace E2ETest.Namespace
104104
entity.Property(e => e.varcharColumn).HasColumnType("varchar(1)");
105105

106106
entity.Property(e => e.varcharMaxColumn).HasColumnType("varchar(max)");
107+
108+
entity.Property(e => e.xmlColumn).HasColumnType("xml");
107109
});
108110

109111
modelBuilder.Entity<MultipleFKsDependent>(entity =>

test/Microsoft.EntityFrameworkCore.SqlServer.Design.FunctionalTests/ReverseEngineering/Expected/Attributes/AllDataTypes.expected

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ namespace E2ETest.Namespace
5252
public byte[] varbinaryMaxColumn { get; set; }
5353
public byte[] timestampColumn { get; set; }
5454
public Guid? uniqueidentifierColumn { get; set; }
55+
public string xmlColumn { get; set; }
5556
public string typeAliasColumn { get; set; }
5657
[MaxLength(1)]
5758
public byte[] binaryVaryingColumn { get; set; }

test/Microsoft.EntityFrameworkCore.SqlServer.Design.FunctionalTests/ReverseEngineering/Expected/Attributes/AttributesContext.expected

+2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ namespace E2ETest.Namespace
8484
entity.Property(e => e.varcharColumn).HasColumnType("varchar(1)");
8585

8686
entity.Property(e => e.varcharMaxColumn).HasColumnType("varchar(max)");
87+
88+
entity.Property(e => e.xmlColumn).HasColumnType("xml");
8789
});
8890

8991
modelBuilder.Entity<MultipleFKsDependent>(entity =>

test/Microsoft.EntityFrameworkCore.SqlServer.Design.FunctionalTests/ReverseEngineering/SqlServerE2ETests.cs

-2
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ public void E2ETest_UseAttributesInsteadOfFluentApi()
150150
RelationalDesignStrings.CannotFindTypeMappingForColumn("dbo.AllDataTypes.geometryColumn", "geometry"),
151151
RelationalDesignStrings.CannotFindTypeMappingForColumn("dbo.AllDataTypes.hierarchyidColumn", "hierarchyid"),
152152
RelationalDesignStrings.CannotFindTypeMappingForColumn("dbo.AllDataTypes.sql_variantColumn", "sql_variant"),
153-
RelationalDesignStrings.CannotFindTypeMappingForColumn("dbo.AllDataTypes.xmlColumn", "xml"),
154153
RelationalDesignStrings.UnableToScaffoldIndexMissingProperty("IX_UnscaffoldableIndex"),
155154
SqlServerDesignStrings.DataTypeDoesNotAllowSqlServerIdentityStrategy("dbo.PropertyConfiguration.PropertyConfigurationID", "tinyint"),
156155
RelationalDesignStrings.CannotFindTypeMappingForColumn("dbo.TableWithUnmappablePrimaryKeyColumn.TableWithUnmappablePrimaryKeyColumnID", "hierarchyid"),
@@ -199,7 +198,6 @@ public void E2ETest_AllFluentApi()
199198
RelationalDesignStrings.CannotFindTypeMappingForColumn("dbo.AllDataTypes.geometryColumn", "geometry"),
200199
RelationalDesignStrings.CannotFindTypeMappingForColumn("dbo.AllDataTypes.hierarchyidColumn", "hierarchyid"),
201200
RelationalDesignStrings.CannotFindTypeMappingForColumn("dbo.AllDataTypes.sql_variantColumn", "sql_variant"),
202-
RelationalDesignStrings.CannotFindTypeMappingForColumn("dbo.AllDataTypes.xmlColumn", "xml"),
203201
RelationalDesignStrings.UnableToScaffoldIndexMissingProperty("IX_UnscaffoldableIndex"),
204202
SqlServerDesignStrings.DataTypeDoesNotAllowSqlServerIdentityStrategy("dbo.PropertyConfiguration.PropertyConfigurationID", "tinyint"),
205203
RelationalDesignStrings.CannotFindTypeMappingForColumn("dbo.TableWithUnmappablePrimaryKeyColumn.TableWithUnmappablePrimaryKeyColumnID", "hierarchyid"),

0 commit comments

Comments
 (0)