Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#12482 Fix batch inserts using with different types on a sql_variant column #24111

Merged
merged 2 commits into from
Feb 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class SqlServerSqlVariantTypeMapping : RelationalTypeMapping
/// </summary>
public SqlServerSqlVariantTypeMapping(
[NotNull] string storeType)
: base(storeType, typeof(object))
: base(storeType, typeof(object), System.Data.DbType.Object)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -696,8 +696,8 @@ public virtual void Can_insert_and_read_back_all_mapped_data_types()
@p32='-128'
@p33='128' (Size = 1)
@p34='79'
@p35='887876'
@p36='Bang!' (Nullable = false) (Size = 5)
@p35='887876' (DbType = Object)
@p36='Bang!' (Nullable = false) (Size = 5) (DbType = Object)
@p37='Your' (Nullable = false) (Size = 8000) (DbType = AnsiString)
@p38='strong' (Nullable = false) (Size = 8000) (DbType = AnsiString)
@p39='help' (Nullable = false) (Size = 4000)
Expand Down Expand Up @@ -887,8 +887,8 @@ public virtual void Can_insert_and_read_back_all_mapped_data_types_with_square_b
@p26='-128'
@p27='128' (Size = 1)
@p28='79'
@p29='887876'
@p30='Bang!' (Nullable = false) (Size = 5)
@p29='887876' (DbType = Object)
@p30='Bang!' (Nullable = false) (Size = 5) (DbType = Object)
@p31='Gumball Rules OK!' (Nullable = false) (Size = 4000)
@p32='"
+ entity.StringAsNvarcharMax
Expand Down Expand Up @@ -1056,8 +1056,8 @@ public virtual void Can_insert_and_read_back_all_mapped_nullable_data_types()
@p32='-128' (Nullable = true)
@p33='128' (Nullable = true) (Size = 1)
@p34='79' (Nullable = true)
@p35='887876' (Nullable = true)
@p36='Bang!' (Size = 5)
@p35='887876' (Nullable = true) (DbType = Object)
@p36='Bang!' (Size = 5) (DbType = Object)
@p37='Your' (Size = 8000) (DbType = AnsiString)
@p38='strong' (Size = 8000) (DbType = AnsiString)
@p39='help' (Size = 4000)
Expand Down Expand Up @@ -1244,8 +1244,8 @@ public virtual void Can_insert_and_read_back_all_mapped_data_types_set_to_null()
@p32=NULL (DbType = Int16)
@p33=NULL (DbType = Byte)
@p34=NULL (DbType = Int16)
@p35=NULL
@p36=NULL
@p35=NULL (DbType = Object)
@p36=NULL (DbType = Object)
@p37=NULL (Size = 8000) (DbType = AnsiString)
@p38=NULL (Size = 8000) (DbType = AnsiString)
@p39=NULL (Size = 4000)
Expand Down Expand Up @@ -1825,8 +1825,8 @@ public virtual void Can_insert_and_read_back_all_mapped_data_types_with_identity
@p32='-128'
@p33='128' (Size = 1)
@p34='79'
@p35='887876'
@p36='Bang!' (Nullable = false) (Size = 5)
@p35='887876' (DbType = Object)
@p36='Bang!' (Nullable = false) (Size = 5) (DbType = Object)
@p37='Your' (Nullable = false) (Size = 8000) (DbType = AnsiString)
@p38='strong' (Nullable = false) (Size = 8000) (DbType = AnsiString)
@p39='help' (Nullable = false) (Size = 4000)
Expand Down Expand Up @@ -2013,8 +2013,8 @@ public virtual void Can_insert_and_read_back_all_mapped_nullable_data_types_with
@p32='-128' (Nullable = true)
@p33='128' (Nullable = true) (Size = 1)
@p34='79' (Nullable = true)
@p35='887876' (Nullable = true)
@p36='Bang!' (Size = 5)
@p35='887876' (Nullable = true) (DbType = Object)
@p36='Bang!' (Size = 5) (DbType = Object)
@p37='Your' (Size = 8000) (DbType = AnsiString)
@p38='strong' (Size = 8000) (DbType = AnsiString)
@p39='help' (Size = 4000)
Expand Down Expand Up @@ -2201,8 +2201,8 @@ public virtual void Can_insert_and_read_back_all_mapped_data_types_set_to_null_w
@p32=NULL (DbType = Int16)
@p33=NULL (DbType = Byte)
@p34=NULL (DbType = Int16)
@p35=NULL
@p36=NULL
@p35=NULL (DbType = Object)
@p36=NULL (DbType = Object)
@p37=NULL (Size = 8000) (DbType = AnsiString)
@p38=NULL (Size = 8000) (DbType = AnsiString)
@p39=NULL (Size = 4000)
Expand Down
66 changes: 66 additions & 0 deletions test/EFCore.SqlServer.FunctionalTests/Query/QueryBugsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9228,6 +9228,72 @@ void WorkLoop()

#endregion Issue22841

#region Issue12482

[ConditionalFact]
public virtual async Task Batch_insert_with_sqlvariant_different_types_12482()
{
var contextFactory = await InitializeAsync<MyContext12482>();

using (var context = contextFactory.CreateContext())
{
context.AddRange(
new MyContext12482.BaseEntity12482 { Value = 10.0999 },
new MyContext12482.BaseEntity12482 { Value = -12345 },
new MyContext12482.BaseEntity12482 { Value = "String Value" },
new MyContext12482.BaseEntity12482 { Value = new DateTime(2020, 1, 1) });

context.SaveChanges();

AssertSql(
@"@p0='10.0999' (Nullable = true) (DbType = Object)
@p1='-12345' (Nullable = true) (DbType = Object)
@p2='String Value' (Size = 12) (DbType = Object)
@p3='2020-01-01T00:00:00.0000000' (Nullable = true) (DbType = Object)

SET NOCOUNT ON;
DECLARE @inserted0 TABLE ([Id] int, [_Position] [int]);
MERGE [BaseEntities] USING (
VALUES (@p0, 0),
(@p1, 1),
(@p2, 2),
(@p3, 3)) AS i ([Value], _Position) ON 1=0
WHEN NOT MATCHED THEN
INSERT ([Value])
VALUES (i.[Value])
OUTPUT INSERTED.[Id], i._Position
INTO @inserted0;

SELECT [t].[Id] FROM [BaseEntities] t
INNER JOIN @inserted0 i ON ([t].[Id] = [i].[Id])
ORDER BY [i].[_Position];");
}
}

protected class MyContext12482 : DbContext
{
public virtual DbSet<BaseEntity12482> BaseEntities { get; set; }

public MyContext12482(DbContextOptions options)
: base(options)
{
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<BaseEntity12482>();
}

public class BaseEntity12482
{
public int Id { get; set; }
[Column(TypeName = "sql_variant")]
public object Value { get; set; }
}
}

#endregion

protected override string StoreName => "QueryBugsTest";
protected TestSqlLoggerFactory TestSqlLoggerFactory
=> (TestSqlLoggerFactory)ListLoggerFactory;
Expand Down