From b7a8b04d5e8ecdd7d30baa8db67d997290ccb620 Mon Sep 17 00:00:00 2001 From: Svyatoslav Danyliv Date: Thu, 3 Jun 2021 11:00:56 +0300 Subject: [PATCH 1/4] Fix for #143. Changed Identity handling logic. --- .../EFCoreMetadataReader.cs | 7 +- ...qToDB.EntityFrameworkCore.BaseTests.csproj | 1 + ...DB.EntityFrameworkCore.SQLite.Tests.csproj | 4 - .../Identity/EfCoreSqliteInMemoryDbFactory.cs | 124 ++++++++++++++++++ .../Models/Identity/IdentityDbContext.cs | 13 ++ .../Models/Identity/Person.cs | 10 ++ .../SQLiteTests.cs | 30 ++++- 7 files changed, 179 insertions(+), 10 deletions(-) create mode 100644 Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/Models/Identity/EfCoreSqliteInMemoryDbFactory.cs create mode 100644 Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/Models/Identity/IdentityDbContext.cs create mode 100644 Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/Models/Identity/Person.cs diff --git a/Source/LinqToDB.EntityFrameworkCore/EFCoreMetadataReader.cs b/Source/LinqToDB.EntityFrameworkCore/EFCoreMetadataReader.cs index 5d87616..4b0c1f0 100644 --- a/Source/LinqToDB.EntityFrameworkCore/EFCoreMetadataReader.cs +++ b/Source/LinqToDB.EntityFrameworkCore/EFCoreMetadataReader.cs @@ -160,11 +160,6 @@ public T[] GetAttributes(Type type, MemberInfo memberInfo, bool inherit = tru var isIdentity = prop.GetAnnotations() .Any(a => a.Name.EndsWith(":ValueGenerationStrategy") && a.Value?.ToString() == "IdentityColumn"); - if (!isIdentity && isPrimaryKey) - { - isIdentity = prop.ValueGenerated == ValueGenerated.OnAdd; - } - var storeObjectId = GetStoreObjectIdentifier(et); return new T[]{(T)(Attribute) new ColumnAttribute @@ -175,6 +170,8 @@ public T[] GetAttributes(Type type, MemberInfo memberInfo, bool inherit = tru DbType = prop.GetColumnType(), IsPrimaryKey = isPrimaryKey, PrimaryKeyOrder = primaryKeyOrder, + SkipOnInsert = prop.ValueGenerated == ValueGenerated.OnAdd || prop.ValueGenerated == ValueGenerated.OnAddOrUpdate, + SkipOnUpdate = prop.ValueGenerated == ValueGenerated.OnUpdate || prop.ValueGenerated == ValueGenerated.OnAddOrUpdate, IsIdentity = isIdentity, }}; } diff --git a/Tests/LinqToDB.EntityFrameworkCore.BaseTests/LinqToDB.EntityFrameworkCore.BaseTests.csproj b/Tests/LinqToDB.EntityFrameworkCore.BaseTests/LinqToDB.EntityFrameworkCore.BaseTests.csproj index f1adce0..b453528 100644 --- a/Tests/LinqToDB.EntityFrameworkCore.BaseTests/LinqToDB.EntityFrameworkCore.BaseTests.csproj +++ b/Tests/LinqToDB.EntityFrameworkCore.BaseTests/LinqToDB.EntityFrameworkCore.BaseTests.csproj @@ -9,6 +9,7 @@ + diff --git a/Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests.csproj b/Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests.csproj index c93ae49..a518219 100644 --- a/Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests.csproj +++ b/Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests.csproj @@ -13,10 +13,6 @@ - - - - diff --git a/Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/Models/Identity/EfCoreSqliteInMemoryDbFactory.cs b/Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/Models/Identity/EfCoreSqliteInMemoryDbFactory.cs new file mode 100644 index 0000000..16eb234 --- /dev/null +++ b/Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/Models/Identity/EfCoreSqliteInMemoryDbFactory.cs @@ -0,0 +1,124 @@ +using System; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.Data.Sqlite; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +namespace LinqToDB.EntityFrameworkCore.SQLite.Tests.Models.Identity +{ + public sealed class EfCoreSqliteInMemoryDbFactory : IDisposable, IAsyncDisposable + { + private readonly string _connectionString; + private SqliteConnection? _connection; + + public EfCoreSqliteInMemoryDbFactory() + { + _connectionString = "DataSource=:memory:"; + } + + public EfCoreSqliteInMemoryDbFactory(string connectionString) + { + _connectionString = connectionString; + } + + + public async ValueTask DisposeAsync() + { + await Task.Run(Dispose); + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + public T CreateDbContext(bool addVersionGeneratorTrigger = true, Action logger = null) + where T : DbContext + { + _connection = new SqliteConnection(_connectionString); + _connection.Open(); + + var optionsBuilder = new DbContextOptionsBuilder().UseSqlite(_connection); + + if (logger != null) + optionsBuilder.LogTo(logger); + + var context = (T) Activator.CreateInstance(typeof(T), optionsBuilder.Options); + + context?.Database.EnsureCreated(); + + if (!addVersionGeneratorTrigger) + return context; + + AddVersionTrigger(context); + + return context; + } + + private void AddVersionTrigger(T context) where T : DbContext + { + var tables = context.Model.GetEntityTypes(); + + foreach (var table in tables) + { + var props = table.GetProperties().Where(p => + p.ClrType == typeof(byte[]) && p.ValueGenerated == ValueGenerated.OnAddOrUpdate && + p.IsConcurrencyToken); + + var tableName = table.GetTableName(); + + foreach (var field in props) + { + string[] sqlStrings = + { + $@"CREATE TRIGGER Set{tableName}_{field.Name}OnUpdate + AFTER UPDATE ON {tableName} + BEGIN + UPDATE {tableName} + SET {field.Name} = randomblob(8) + WHERE rowid = NEW.rowid; + END + ", + $@"CREATE TRIGGER Set{tableName}_{field.Name}OnInsert + AFTER INSERT ON {tableName} + BEGIN + UPDATE {tableName} + SET {field.Name} = randomblob(8) + WHERE rowid = NEW.rowid; + END + " + }; + + foreach (var sql in sqlStrings) + { + using var command = _connection.CreateCommand(); + command.CommandText = sql; + command.ExecuteNonQuery(); + } + } + } + } + + private void ReleaseUnmanagedResources() + { + _connection.Dispose(); + } + + private void Dispose(bool disposing) + { + ReleaseUnmanagedResources(); + + if (disposing) + { + } + } + + ~EfCoreSqliteInMemoryDbFactory() + { + Dispose(false); + } + } + +} diff --git a/Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/Models/Identity/IdentityDbContext.cs b/Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/Models/Identity/IdentityDbContext.cs new file mode 100644 index 0000000..f0fb1ee --- /dev/null +++ b/Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/Models/Identity/IdentityDbContext.cs @@ -0,0 +1,13 @@ +using Microsoft.EntityFrameworkCore; + +namespace LinqToDB.EntityFrameworkCore.SQLite.Tests.Models.Identity +{ + public class IdentityDbContext : DbContext + { + public IdentityDbContext(DbContextOptions options) : base(options) + { + } + + public DbSet People { get; set; } = null!; + } +} diff --git a/Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/Models/Identity/Person.cs b/Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/Models/Identity/Person.cs new file mode 100644 index 0000000..a452504 --- /dev/null +++ b/Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/Models/Identity/Person.cs @@ -0,0 +1,10 @@ +using System; + +namespace LinqToDB.EntityFrameworkCore.SQLite.Tests.Models.Identity +{ + public class Person + { + public Guid Id { get; set; } + public string Name { get; set; } = null!; + } +} diff --git a/Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/SQLiteTests.cs b/Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/SQLiteTests.cs index ef2ed3b..ac74b7d 100644 --- a/Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/SQLiteTests.cs +++ b/Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/SQLiteTests.cs @@ -1,7 +1,10 @@ -using System.Linq; +using System.Collections.Generic; +using System.Linq; +using FluentAssertions; using LinqToDB.Data; using LinqToDB.EntityFrameworkCore.BaseTests; using LinqToDB.EntityFrameworkCore.BaseTests.Models.Northwind; +using LinqToDB.EntityFrameworkCore.SQLite.Tests.Models.Identity; using LinqToDB.EntityFrameworkCore.SQLite.Tests.Models.Northwind; using Microsoft.EntityFrameworkCore; using NUnit.Framework; @@ -53,5 +56,30 @@ public void TestIdentityMapping() } + [Test] + public void TestSqliteDbCreation() + { + var dbFactory = new EfCoreSqliteInMemoryDbFactory(); + + using var context = dbFactory.CreateDbContext(); + + context.AddRange(new List + { + new() {Name = "John Doe"}, + new() {Name = "Jane Doe"} + }); + + context.SaveChanges(); + + var people = context.People.ToList(); + + var connection = context.CreateLinqToDbConnection(); + + var tempTable = connection.CreateTempTable(people, new BulkCopyOptions {KeepIdentity = true}); + + tempTable.ToList().Should().BeEquivalentTo(people); + } + + } } From a18b543113769e448753801221a178bf0d684eaf Mon Sep 17 00:00:00 2001 From: Svyatoslav Danyliv Date: Thu, 3 Jun 2021 16:26:15 +0300 Subject: [PATCH 2/4] Unified Mapping tests. --- .../EFCoreMetadataReader.cs | 22 +++- .../LinqToDBForEFToolsImplDefault.cs | 11 +- .../linq2db.EntityFrameworkCore.csproj | 2 +- .../ForMappingTestsBase.cs | 91 +++++++++++++ .../Logging/TestLogger.cs | 2 + .../ForMapping/ForMappingContextBase.cs | 15 +++ .../Models/ForMapping/NoIdentity.cs} | 4 +- .../Models/ForMapping/WithIdentity.cs | 8 ++ .../TestUtils.cs | 2 + .../ForMappingTests.cs | 31 +++++ ...tityFrameworkCore.PomeloMySql.Tests.csproj | 4 - .../Models/ForMapping/ForMappingContext.cs | 30 +++++ .../ForMappingTests.cs | 38 ++++++ .../Models/ForMapping/ForMappingContext.cs | 30 +++++ .../Models/NpgSqlEntities/EntityWithArrays.cs | 13 ++ .../NpgSqlEntities/NpgSqlEnititesContext.cs | 1 + .../NpgSqlTests.cs | 33 +++++ .../SampleTests/IdTests.cs | 4 +- .../ForMappingTests.cs | 26 ++++ .../Models/ForMapping/ForMappingContext.cs | 30 +++++ .../Identity/EfCoreSqliteInMemoryDbFactory.cs | 124 ------------------ .../Models/Identity/IdentityDbContext.cs | 13 -- .../SQLiteTests.cs | 48 +------ .../ForMappingTests.cs | 27 ++++ .../IssueTests.cs | 1 + .../Models/ForMapping/ForMappingContext.cs | 30 +++++ .../ToolsTests.cs | 45 +------ 27 files changed, 443 insertions(+), 242 deletions(-) create mode 100644 Tests/LinqToDB.EntityFrameworkCore.BaseTests/ForMappingTestsBase.cs create mode 100644 Tests/LinqToDB.EntityFrameworkCore.BaseTests/Models/ForMapping/ForMappingContextBase.cs rename Tests/{LinqToDB.EntityFrameworkCore.SQLite.Tests/Models/Identity/Person.cs => LinqToDB.EntityFrameworkCore.BaseTests/Models/ForMapping/NoIdentity.cs} (50%) create mode 100644 Tests/LinqToDB.EntityFrameworkCore.BaseTests/Models/ForMapping/WithIdentity.cs create mode 100644 Tests/LinqToDB.EntityFrameworkCore.PomeloMySql.Tests/ForMappingTests.cs create mode 100644 Tests/LinqToDB.EntityFrameworkCore.PomeloMySql.Tests/Models/ForMapping/ForMappingContext.cs create mode 100644 Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/ForMappingTests.cs create mode 100644 Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/Models/ForMapping/ForMappingContext.cs create mode 100644 Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/Models/NpgSqlEntities/EntityWithArrays.cs create mode 100644 Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/ForMappingTests.cs create mode 100644 Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/Models/ForMapping/ForMappingContext.cs delete mode 100644 Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/Models/Identity/EfCoreSqliteInMemoryDbFactory.cs delete mode 100644 Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/Models/Identity/IdentityDbContext.cs create mode 100644 Tests/LinqToDB.EntityFrameworkCore.SqlServer.Tests/ForMappingTests.cs create mode 100644 Tests/LinqToDB.EntityFrameworkCore.SqlServer.Tests/Models/ForMapping/ForMappingContext.cs diff --git a/Source/LinqToDB.EntityFrameworkCore/EFCoreMetadataReader.cs b/Source/LinqToDB.EntityFrameworkCore/EFCoreMetadataReader.cs index 4b0c1f0..ce9383c 100644 --- a/Source/LinqToDB.EntityFrameworkCore/EFCoreMetadataReader.cs +++ b/Source/LinqToDB.EntityFrameworkCore/EFCoreMetadataReader.cs @@ -158,7 +158,25 @@ public T[] GetAttributes(Type type, MemberInfo memberInfo, bool inherit = tru } var isIdentity = prop.GetAnnotations() - .Any(a => a.Name.EndsWith(":ValueGenerationStrategy") && a.Value?.ToString() == "IdentityColumn"); + .Any(a => + { + if (a.Name.EndsWith(":ValueGenerationStrategy")) + return a.Value?.ToString().Contains("Identity") == true; + + if (a.Name.EndsWith(":Autoincrement")) + return a.Value is bool b && b; + + // for postgres + if (a.Name == "Relational:DefaultValueSql") + { + if (a.Value is string str) + { + return str.ToLower().Contains("nextval"); + } + } + + return false; + }); var storeObjectId = GetStoreObjectIdentifier(et); @@ -170,8 +188,6 @@ public T[] GetAttributes(Type type, MemberInfo memberInfo, bool inherit = tru DbType = prop.GetColumnType(), IsPrimaryKey = isPrimaryKey, PrimaryKeyOrder = primaryKeyOrder, - SkipOnInsert = prop.ValueGenerated == ValueGenerated.OnAdd || prop.ValueGenerated == ValueGenerated.OnAddOrUpdate, - SkipOnUpdate = prop.ValueGenerated == ValueGenerated.OnUpdate || prop.ValueGenerated == ValueGenerated.OnAddOrUpdate, IsIdentity = isIdentity, }}; } diff --git a/Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFToolsImplDefault.cs b/Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFToolsImplDefault.cs index dfd700f..0caba1e 100644 --- a/Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFToolsImplDefault.cs +++ b/Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFToolsImplDefault.cs @@ -17,6 +17,7 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Diagnostics; +using Microsoft.Extensions.Caching.Memory; namespace LinqToDB.EntityFrameworkCore { @@ -84,10 +85,10 @@ public override int GetHashCode() #endregion } - readonly ConcurrentDictionary _knownProviders = new ConcurrentDictionary(); + readonly ConcurrentDictionary _knownProviders = new(); - private readonly MemoryCache _schemaCache = new MemoryCache( - new MemoryCacheOptions + private readonly MemoryCache _schemaCache = new( + new Microsoft.Extensions.Caching.Memory.MemoryCacheOptions() { ExpirationScanFrequency = TimeSpan.FromHours(1.0) }); @@ -455,6 +456,10 @@ public virtual void DefineConvertors( if (modelType.IsEnum) continue; + // skipping arrays + if (modelType.IsArray) + continue; + MapEFCoreType(modelType); if (modelType.IsValueType && !typeof(Nullable<>).IsSameOrParentOf(modelType)) MapEFCoreType(typeof(Nullable<>).MakeGenericType(modelType)); diff --git a/Source/LinqToDB.EntityFrameworkCore/linq2db.EntityFrameworkCore.csproj b/Source/LinqToDB.EntityFrameworkCore/linq2db.EntityFrameworkCore.csproj index 29d6101..7dbdaf9 100644 --- a/Source/LinqToDB.EntityFrameworkCore/linq2db.EntityFrameworkCore.csproj +++ b/Source/LinqToDB.EntityFrameworkCore/linq2db.EntityFrameworkCore.csproj @@ -17,7 +17,7 @@ - + diff --git a/Tests/LinqToDB.EntityFrameworkCore.BaseTests/ForMappingTestsBase.cs b/Tests/LinqToDB.EntityFrameworkCore.BaseTests/ForMappingTestsBase.cs new file mode 100644 index 0000000..7e230e2 --- /dev/null +++ b/Tests/LinqToDB.EntityFrameworkCore.BaseTests/ForMappingTestsBase.cs @@ -0,0 +1,91 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using FluentAssertions; +using LinqToDB.Data; +using LinqToDB.EntityFrameworkCore.BaseTests.Models.ForMapping; +using NUnit.Framework; + +namespace LinqToDB.EntityFrameworkCore.BaseTests +{ + public abstract class ForMappingTestsBase : TestsBase + { + public abstract ForMappingContextBase CreateContext(); + + [Test] + public virtual void TestIdentityMapping() + { + using var context = CreateContext(); + using var connection = context.CreateLinqToDbConnection(); + + var ed = connection.MappingSchema.GetEntityDescriptor(typeof(WithIdentity)); + var pk = ed.Columns.Where(c => c.IsPrimaryKey).Single(); + + pk.IsIdentity.Should().BeTrue(); + } + + [Test] + public virtual void TestNoIdentityMapping() + { + using var context = CreateContext(); + using var connection = context.CreateLinqToDbConnection(); + + var ed = connection.MappingSchema.GetEntityDescriptor(typeof(NoIdentity)); + var pk = ed.Columns.Where(c => c.IsPrimaryKey).Single(); + + pk.IsIdentity.Should().BeFalse(); + } + + [Test] + public virtual void TestTableCreation() + { + using var context = CreateContext(); + using var connection = context.CreateLinqToDbConnection(); + + using var t1 = connection.CreateTempTable(); + using var t2 = connection.CreateTempTable(); + } + + + [Test] + public virtual void TestBulkCopyNoIdentity() + { + using var context = CreateContext(); + using var connection = context.CreateLinqToDbConnection(); + + using var t = connection.CreateTempTable(); + + var items = new List() + { + new() {Id = Guid.NewGuid(), Name = "John Doe"}, + new() {Id = Guid.NewGuid(), Name = "Jane Doe"} + }; + + t.BulkCopy(items); + + + items.Should().BeEquivalentTo(t); + } + + [Test] + public virtual void TestBulkCopyWithIdentity() + { + using var context = CreateContext(); + using var connection = context.CreateLinqToDbConnection(); + + using var t = connection.CreateTempTable(); + + var items = new List() + { + new() {Id = 1, Name = "John Doe"}, + new() {Id = 2, Name = "Jane Doe"} + }; + + t.BulkCopy(items); + + + t.Should().HaveCount(items.Count); + } + + } +} diff --git a/Tests/LinqToDB.EntityFrameworkCore.BaseTests/Logging/TestLogger.cs b/Tests/LinqToDB.EntityFrameworkCore.BaseTests/Logging/TestLogger.cs index 9eccefe..39a8f48 100644 --- a/Tests/LinqToDB.EntityFrameworkCore.BaseTests/Logging/TestLogger.cs +++ b/Tests/LinqToDB.EntityFrameworkCore.BaseTests/Logging/TestLogger.cs @@ -13,7 +13,9 @@ internal class TestLogger : ILogger private static readonly string _newLineWithMessagePadding; // ConsoleColor does not have a value to specify the 'Default' color +#pragma warning disable 649 private readonly ConsoleColor? DefaultConsoleColor; +#pragma warning restore 649 private readonly string _name; diff --git a/Tests/LinqToDB.EntityFrameworkCore.BaseTests/Models/ForMapping/ForMappingContextBase.cs b/Tests/LinqToDB.EntityFrameworkCore.BaseTests/Models/ForMapping/ForMappingContextBase.cs new file mode 100644 index 0000000..07bbcce --- /dev/null +++ b/Tests/LinqToDB.EntityFrameworkCore.BaseTests/Models/ForMapping/ForMappingContextBase.cs @@ -0,0 +1,15 @@ +using Microsoft.EntityFrameworkCore; + +namespace LinqToDB.EntityFrameworkCore.BaseTests.Models.ForMapping +{ + public abstract class ForMappingContextBase : DbContext + { + protected ForMappingContextBase(DbContextOptions options) : base(options) + { + } + + public DbSet WithIdentity { get; set; } = null!; + public DbSet NoIdentity { get; set; } = null!; + + } +} diff --git a/Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/Models/Identity/Person.cs b/Tests/LinqToDB.EntityFrameworkCore.BaseTests/Models/ForMapping/NoIdentity.cs similarity index 50% rename from Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/Models/Identity/Person.cs rename to Tests/LinqToDB.EntityFrameworkCore.BaseTests/Models/ForMapping/NoIdentity.cs index a452504..636bacd 100644 --- a/Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/Models/Identity/Person.cs +++ b/Tests/LinqToDB.EntityFrameworkCore.BaseTests/Models/ForMapping/NoIdentity.cs @@ -1,8 +1,8 @@ using System; -namespace LinqToDB.EntityFrameworkCore.SQLite.Tests.Models.Identity +namespace LinqToDB.EntityFrameworkCore.BaseTests.Models.ForMapping { - public class Person + public class NoIdentity { public Guid Id { get; set; } public string Name { get; set; } = null!; diff --git a/Tests/LinqToDB.EntityFrameworkCore.BaseTests/Models/ForMapping/WithIdentity.cs b/Tests/LinqToDB.EntityFrameworkCore.BaseTests/Models/ForMapping/WithIdentity.cs new file mode 100644 index 0000000..e30c583 --- /dev/null +++ b/Tests/LinqToDB.EntityFrameworkCore.BaseTests/Models/ForMapping/WithIdentity.cs @@ -0,0 +1,8 @@ +namespace LinqToDB.EntityFrameworkCore.BaseTests.Models.ForMapping +{ + public class WithIdentity + { + public int Id { get; set; } + public string Name { get; set; } = null!; + } +} diff --git a/Tests/LinqToDB.EntityFrameworkCore.BaseTests/TestUtils.cs b/Tests/LinqToDB.EntityFrameworkCore.BaseTests/TestUtils.cs index 5678d4e..1a05bc3 100644 --- a/Tests/LinqToDB.EntityFrameworkCore.BaseTests/TestUtils.cs +++ b/Tests/LinqToDB.EntityFrameworkCore.BaseTests/TestUtils.cs @@ -15,7 +15,9 @@ public class TestUtils .AddTestLogger(o => { +#pragma warning disable 618 o.IncludeScopes = true; +#pragma warning restore 618 o.FormatterName = ConsoleFormatterNames.Simple; }); }); diff --git a/Tests/LinqToDB.EntityFrameworkCore.PomeloMySql.Tests/ForMappingTests.cs b/Tests/LinqToDB.EntityFrameworkCore.PomeloMySql.Tests/ForMappingTests.cs new file mode 100644 index 0000000..4c6ec5b --- /dev/null +++ b/Tests/LinqToDB.EntityFrameworkCore.PomeloMySql.Tests/ForMappingTests.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using FluentAssertions; +using LinqToDB.Data; +using LinqToDB.EntityFrameworkCore.BaseTests; +using LinqToDB.EntityFrameworkCore.BaseTests.Models.ForMapping; +using LinqToDB.EntityFrameworkCore.PomeloMySql.Tests.Models.ForMapping; +using Microsoft.EntityFrameworkCore; + +namespace LinqToDB.EntityFrameworkCore.PomeloMySql.Tests +{ + public class ForMappingTests : ForMappingTestsBase + { + public override ForMappingContextBase CreateContext() + { + var optionsBuilder = new DbContextOptionsBuilder(); + optionsBuilder.UseMySql("Server=DBHost;Port=3306;Database=TestData;Uid=TestUser;Pwd=TestPassword;charset=utf8;"); + optionsBuilder.UseLoggerFactory(TestUtils.LoggerFactory); + + var options = optionsBuilder.Options; + var ctx = new ForMappingContext(options); + + //ctx.Database.EnsureDeleted(); + ctx.Database.EnsureCreated(); + + return ctx; + } + + } +} diff --git a/Tests/LinqToDB.EntityFrameworkCore.PomeloMySql.Tests/LinqToDB.EntityFrameworkCore.PomeloMySql.Tests.csproj b/Tests/LinqToDB.EntityFrameworkCore.PomeloMySql.Tests/LinqToDB.EntityFrameworkCore.PomeloMySql.Tests.csproj index f6b3f59..544d66a 100644 --- a/Tests/LinqToDB.EntityFrameworkCore.PomeloMySql.Tests/LinqToDB.EntityFrameworkCore.PomeloMySql.Tests.csproj +++ b/Tests/LinqToDB.EntityFrameworkCore.PomeloMySql.Tests/LinqToDB.EntityFrameworkCore.PomeloMySql.Tests.csproj @@ -17,8 +17,4 @@ - - - - diff --git a/Tests/LinqToDB.EntityFrameworkCore.PomeloMySql.Tests/Models/ForMapping/ForMappingContext.cs b/Tests/LinqToDB.EntityFrameworkCore.PomeloMySql.Tests/Models/ForMapping/ForMappingContext.cs new file mode 100644 index 0000000..ed5782e --- /dev/null +++ b/Tests/LinqToDB.EntityFrameworkCore.PomeloMySql.Tests/Models/ForMapping/ForMappingContext.cs @@ -0,0 +1,30 @@ +using LinqToDB.EntityFrameworkCore.BaseTests.Models.ForMapping; +using Microsoft.EntityFrameworkCore; + +namespace LinqToDB.EntityFrameworkCore.PomeloMySql.Tests.Models.ForMapping +{ + public class ForMappingContext : ForMappingContextBase + { + + public ForMappingContext(DbContextOptions options) : base(options) + { + + } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity(b => + { + b.HasKey(e => e.Id); + + b.Property(e => e.Id) + .UseMySqlIdentityColumn(); + }); + + modelBuilder.Entity(b => + { + b.HasKey(e => e.Id); + }); + } + } +} diff --git a/Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/ForMappingTests.cs b/Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/ForMappingTests.cs new file mode 100644 index 0000000..277e5ab --- /dev/null +++ b/Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/ForMappingTests.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using FluentAssertions; +using LinqToDB.Data; +using LinqToDB.EntityFrameworkCore.BaseTests; +using LinqToDB.EntityFrameworkCore.BaseTests.Models.ForMapping; +using LinqToDB.EntityFrameworkCore.PostgreSQL.Tests.Models.ForMapping; +using Microsoft.EntityFrameworkCore; +using NUnit.Framework; + +namespace LinqToDB.EntityFrameworkCore.PostgreSQL.Tests +{ + [TestFixture] + public class ForMappingTests : ForMappingTestsBase + { + public override ForMappingContextBase CreateContext() + { + var optionsBuilder = new DbContextOptionsBuilder(); + optionsBuilder.UseNpgsql("Server=DBHost;Port=5432;Database=ForMapping;User Id=postgres;Password=TestPassword;Pooling=true;MinPoolSize=10;MaxPoolSize=100;"); + optionsBuilder.UseLoggerFactory(TestUtils.LoggerFactory); + + var options = optionsBuilder.Options; + var ctx = new ForMappingContext(options); + + //ctx.Database.EnsureDeleted(); + ctx.Database.EnsureCreated(); + + return ctx; + } + + //Disabled, we cannot create such identity table. + public override void TestBulkCopyWithIdentity() + { + } + + } +} diff --git a/Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/Models/ForMapping/ForMappingContext.cs b/Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/Models/ForMapping/ForMappingContext.cs new file mode 100644 index 0000000..4d1b487 --- /dev/null +++ b/Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/Models/ForMapping/ForMappingContext.cs @@ -0,0 +1,30 @@ +using LinqToDB.EntityFrameworkCore.BaseTests.Models.ForMapping; +using Microsoft.EntityFrameworkCore; + +namespace LinqToDB.EntityFrameworkCore.PostgreSQL.Tests.Models.ForMapping +{ + public class ForMappingContext : ForMappingContextBase + { + + public ForMappingContext(DbContextOptions options) : base(options) + { + + } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity(b => + { + b.HasKey(e => e.Id); + + b.Property(e => e.Id) + .UseIdentityAlwaysColumn(); + }); + + modelBuilder.Entity(b => + { + b.HasKey(e => e.Id); + }); + } + } +} diff --git a/Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/Models/NpgSqlEntities/EntityWithArrays.cs b/Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/Models/NpgSqlEntities/EntityWithArrays.cs new file mode 100644 index 0000000..33f0b2a --- /dev/null +++ b/Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/Models/NpgSqlEntities/EntityWithArrays.cs @@ -0,0 +1,13 @@ +using System; +using System.ComponentModel.DataAnnotations; + +namespace LinqToDB.EntityFrameworkCore.PostgreSQL.Tests.Models.NpgSqlEntities +{ + public class EntityWithArrays + { + [Key] + public int Id { get; set; } + + public Guid[] Guids { get; set; } = null!; + } +} diff --git a/Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/Models/NpgSqlEntities/NpgSqlEnititesContext.cs b/Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/Models/NpgSqlEntities/NpgSqlEnititesContext.cs index c02c2d4..7a82cec 100644 --- a/Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/Models/NpgSqlEntities/NpgSqlEnititesContext.cs +++ b/Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/Models/NpgSqlEntities/NpgSqlEnititesContext.cs @@ -23,6 +23,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) } public virtual DbSet Events { get; set; } = null!; + public virtual DbSet EntityWithArrays { get; set; } = null!; } } diff --git a/Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/NpgSqlTests.cs b/Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/NpgSqlTests.cs index 950af00..5bf238f 100644 --- a/Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/NpgSqlTests.cs +++ b/Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/NpgSqlTests.cs @@ -1,6 +1,8 @@ using System; using System.Linq; +using FluentAssertions; using LinqToDB.Data; +using LinqToDB.DataProvider.PostgreSQL; using LinqToDB.EntityFrameworkCore.BaseTests; using LinqToDB.EntityFrameworkCore.PostgreSQL.Tests.Models.NpgSqlEntities; using Microsoft.EntityFrameworkCore; @@ -67,5 +69,36 @@ public void TestViewMapping() var l2dbResult = query.ToLinqToDB().ToArray(); } } + + [Test] + public void TestArray() + { + using (var db = CreateNpgSqlEntitiesContext()) + { + var guids = new Guid[] { Guid.Parse("271425b1-ebe8-400d-b71d-a6e47a460ae3"), + Guid.Parse("b75de94e-6d7b-4c70-bfa1-f8639a6a5b35") }; + + var query = + from m in db.EntityWithArrays.ToLinqToDBTable() + where Sql.Ext.PostgreSQL().Overlaps(m.Guids, guids) + select m; + + query.Invoking(q => q.ToArray()).Should().NotThrow(); + } + } + + [Test] + public void TestIdentityMapping() + { + using (var ctx = CreateNpgSqlEntitiesContext()) + using (var db = ctx.CreateLinqToDbConnection()) + { + var ed = db.MappingSchema.GetEntityDescriptor(typeof(Event)); + var pk = ed.Columns.Where(c => c.IsPrimaryKey).Single(); + + pk.IsIdentity.Should().BeTrue(); + } + } + } } diff --git a/Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/SampleTests/IdTests.cs b/Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/SampleTests/IdTests.cs index 3f08559..03192b7 100644 --- a/Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/SampleTests/IdTests.cs +++ b/Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/SampleTests/IdTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Diagnostics; using System.Linq; using FluentAssertions; @@ -20,7 +20,7 @@ public IdTests() .ReplaceService() .UseLoggerFactory(TestUtils.LoggerFactory) .EnableSensitiveDataLogging() - .UseNpgsql("Server=DBHost;Port=5432;Database=TestData;User Id=postgres;Password=TestPassword;Pooling=true;MinPoolSize=10;MaxPoolSize=100;") + .UseNpgsql("Server=DBHost;Port=5432;Database=IdTests;User Id=postgres;Password=TestPassword;Pooling=true;MinPoolSize=10;MaxPoolSize=100;") .Options); _efContext.Database.EnsureDeleted(); _efContext.Database.EnsureCreated(); diff --git a/Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/ForMappingTests.cs b/Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/ForMappingTests.cs new file mode 100644 index 0000000..481d0d4 --- /dev/null +++ b/Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/ForMappingTests.cs @@ -0,0 +1,26 @@ +using LinqToDB.EntityFrameworkCore.BaseTests; +using LinqToDB.EntityFrameworkCore.BaseTests.Models.ForMapping; +using LinqToDB.EntityFrameworkCore.SQLite.Tests.Models.ForMapping; +using Microsoft.EntityFrameworkCore; +using NUnit.Framework; + +namespace LinqToDB.EntityFrameworkCore.SQLite.Tests +{ + [TestFixture] + public class ForMappingTests : ForMappingTestsBase + { + public override ForMappingContextBase CreateContext() + { + var optionsBuilder = new DbContextOptionsBuilder(); + optionsBuilder.UseSqlite("DataSource=:memory:"); + optionsBuilder.UseLoggerFactory(TestUtils.LoggerFactory); + + var options = optionsBuilder.Options; + var ctx = new ForMappingContext(options); + + ctx.Database.EnsureCreated(); + + return ctx; + } + } +} diff --git a/Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/Models/ForMapping/ForMappingContext.cs b/Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/Models/ForMapping/ForMappingContext.cs new file mode 100644 index 0000000..634131a --- /dev/null +++ b/Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/Models/ForMapping/ForMappingContext.cs @@ -0,0 +1,30 @@ +using LinqToDB.EntityFrameworkCore.BaseTests.Models.ForMapping; +using Microsoft.EntityFrameworkCore; + +namespace LinqToDB.EntityFrameworkCore.SQLite.Tests.Models.ForMapping +{ + public class ForMappingContext : ForMappingContextBase + { + + public ForMappingContext(DbContextOptions options) : base(options) + { + + } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity(b => + { + b.HasKey(e => e.Id); + + b.Property(e => e.Id) + .HasAnnotation("Sqlite:Autoincrement", true); + }); + + modelBuilder.Entity(b => + { + b.HasKey(e => e.Id); + }); + } + } +} diff --git a/Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/Models/Identity/EfCoreSqliteInMemoryDbFactory.cs b/Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/Models/Identity/EfCoreSqliteInMemoryDbFactory.cs deleted file mode 100644 index 16eb234..0000000 --- a/Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/Models/Identity/EfCoreSqliteInMemoryDbFactory.cs +++ /dev/null @@ -1,124 +0,0 @@ -using System; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.Data.Sqlite; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Metadata; - -namespace LinqToDB.EntityFrameworkCore.SQLite.Tests.Models.Identity -{ - public sealed class EfCoreSqliteInMemoryDbFactory : IDisposable, IAsyncDisposable - { - private readonly string _connectionString; - private SqliteConnection? _connection; - - public EfCoreSqliteInMemoryDbFactory() - { - _connectionString = "DataSource=:memory:"; - } - - public EfCoreSqliteInMemoryDbFactory(string connectionString) - { - _connectionString = connectionString; - } - - - public async ValueTask DisposeAsync() - { - await Task.Run(Dispose); - } - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - public T CreateDbContext(bool addVersionGeneratorTrigger = true, Action logger = null) - where T : DbContext - { - _connection = new SqliteConnection(_connectionString); - _connection.Open(); - - var optionsBuilder = new DbContextOptionsBuilder().UseSqlite(_connection); - - if (logger != null) - optionsBuilder.LogTo(logger); - - var context = (T) Activator.CreateInstance(typeof(T), optionsBuilder.Options); - - context?.Database.EnsureCreated(); - - if (!addVersionGeneratorTrigger) - return context; - - AddVersionTrigger(context); - - return context; - } - - private void AddVersionTrigger(T context) where T : DbContext - { - var tables = context.Model.GetEntityTypes(); - - foreach (var table in tables) - { - var props = table.GetProperties().Where(p => - p.ClrType == typeof(byte[]) && p.ValueGenerated == ValueGenerated.OnAddOrUpdate && - p.IsConcurrencyToken); - - var tableName = table.GetTableName(); - - foreach (var field in props) - { - string[] sqlStrings = - { - $@"CREATE TRIGGER Set{tableName}_{field.Name}OnUpdate - AFTER UPDATE ON {tableName} - BEGIN - UPDATE {tableName} - SET {field.Name} = randomblob(8) - WHERE rowid = NEW.rowid; - END - ", - $@"CREATE TRIGGER Set{tableName}_{field.Name}OnInsert - AFTER INSERT ON {tableName} - BEGIN - UPDATE {tableName} - SET {field.Name} = randomblob(8) - WHERE rowid = NEW.rowid; - END - " - }; - - foreach (var sql in sqlStrings) - { - using var command = _connection.CreateCommand(); - command.CommandText = sql; - command.ExecuteNonQuery(); - } - } - } - } - - private void ReleaseUnmanagedResources() - { - _connection.Dispose(); - } - - private void Dispose(bool disposing) - { - ReleaseUnmanagedResources(); - - if (disposing) - { - } - } - - ~EfCoreSqliteInMemoryDbFactory() - { - Dispose(false); - } - } - -} diff --git a/Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/Models/Identity/IdentityDbContext.cs b/Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/Models/Identity/IdentityDbContext.cs deleted file mode 100644 index f0fb1ee..0000000 --- a/Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/Models/Identity/IdentityDbContext.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Microsoft.EntityFrameworkCore; - -namespace LinqToDB.EntityFrameworkCore.SQLite.Tests.Models.Identity -{ - public class IdentityDbContext : DbContext - { - public IdentityDbContext(DbContextOptions options) : base(options) - { - } - - public DbSet People { get; set; } = null!; - } -} diff --git a/Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/SQLiteTests.cs b/Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/SQLiteTests.cs index ac74b7d..af110e6 100644 --- a/Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/SQLiteTests.cs +++ b/Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/SQLiteTests.cs @@ -1,13 +1,7 @@ -using System.Collections.Generic; -using System.Linq; -using FluentAssertions; -using LinqToDB.Data; +using LinqToDB.Data; using LinqToDB.EntityFrameworkCore.BaseTests; -using LinqToDB.EntityFrameworkCore.BaseTests.Models.Northwind; -using LinqToDB.EntityFrameworkCore.SQLite.Tests.Models.Identity; using LinqToDB.EntityFrameworkCore.SQLite.Tests.Models.Northwind; using Microsoft.EntityFrameworkCore; -using NUnit.Framework; namespace LinqToDB.EntityFrameworkCore.SQLite.Tests { @@ -40,46 +34,6 @@ private NorthwindContext CreateSQLiteSqlExntitiesContext() ctx.Database.EnsureCreated(); return ctx; } - - - [Test] - public void TestIdentityMapping() - { - using (var ctx = CreateSQLiteSqlExntitiesContext()) - using (var db = ctx.CreateLinqToDbConnection()) - { - var ed = db.MappingSchema.GetEntityDescriptor(typeof(Category)); - var pk = ed.Columns.Where(c => c.IsPrimaryKey).Single(); - - Assert.That(pk.IsIdentity, Is.True); - } - } - - - [Test] - public void TestSqliteDbCreation() - { - var dbFactory = new EfCoreSqliteInMemoryDbFactory(); - - using var context = dbFactory.CreateDbContext(); - - context.AddRange(new List - { - new() {Name = "John Doe"}, - new() {Name = "Jane Doe"} - }); - - context.SaveChanges(); - - var people = context.People.ToList(); - - var connection = context.CreateLinqToDbConnection(); - - var tempTable = connection.CreateTempTable(people, new BulkCopyOptions {KeepIdentity = true}); - - tempTable.ToList().Should().BeEquivalentTo(people); - } - } } diff --git a/Tests/LinqToDB.EntityFrameworkCore.SqlServer.Tests/ForMappingTests.cs b/Tests/LinqToDB.EntityFrameworkCore.SqlServer.Tests/ForMappingTests.cs new file mode 100644 index 0000000..85d7c2b --- /dev/null +++ b/Tests/LinqToDB.EntityFrameworkCore.SqlServer.Tests/ForMappingTests.cs @@ -0,0 +1,27 @@ +using LinqToDB.EntityFrameworkCore.BaseTests; +using LinqToDB.EntityFrameworkCore.BaseTests.Models.ForMapping; +using LinqToDB.EntityFrameworkCore.SqlServer.Tests.Models.ForMapping; +using Microsoft.EntityFrameworkCore; +using NUnit.Framework; + +namespace LinqToDB.EntityFrameworkCore.SqlServer.Tests +{ + [TestFixture] + public class ForMappingTests : ForMappingTestsBase + { + public override ForMappingContextBase CreateContext() + { + var optionsBuilder = new DbContextOptionsBuilder(); + optionsBuilder.UseSqlServer("Server=.;Database=ForMapping;Integrated Security=SSPI"); + optionsBuilder.UseLoggerFactory(TestUtils.LoggerFactory); + + var options = optionsBuilder.Options; + var ctx = new ForMappingContext(options); + + //ctx.Database.EnsureDeleted(); + ctx.Database.EnsureCreated(); + + return ctx; + } + } +} diff --git a/Tests/LinqToDB.EntityFrameworkCore.SqlServer.Tests/IssueTests.cs b/Tests/LinqToDB.EntityFrameworkCore.SqlServer.Tests/IssueTests.cs index 574f6bb..097a9f9 100644 --- a/Tests/LinqToDB.EntityFrameworkCore.SqlServer.Tests/IssueTests.cs +++ b/Tests/LinqToDB.EntityFrameworkCore.SqlServer.Tests/IssueTests.cs @@ -1,4 +1,5 @@ using System.Linq; +using FluentAssertions; using LinqToDB.EntityFrameworkCore.BaseTests; using LinqToDB.EntityFrameworkCore.SqlServer.Tests.Models.IssueModel; using Microsoft.EntityFrameworkCore; diff --git a/Tests/LinqToDB.EntityFrameworkCore.SqlServer.Tests/Models/ForMapping/ForMappingContext.cs b/Tests/LinqToDB.EntityFrameworkCore.SqlServer.Tests/Models/ForMapping/ForMappingContext.cs new file mode 100644 index 0000000..61fc22b --- /dev/null +++ b/Tests/LinqToDB.EntityFrameworkCore.SqlServer.Tests/Models/ForMapping/ForMappingContext.cs @@ -0,0 +1,30 @@ +using LinqToDB.EntityFrameworkCore.BaseTests.Models.ForMapping; +using Microsoft.EntityFrameworkCore; + +namespace LinqToDB.EntityFrameworkCore.SqlServer.Tests.Models.ForMapping +{ + public class ForMappingContext : ForMappingContextBase + { + + public ForMappingContext(DbContextOptions options) : base(options) + { + + } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity(b => + { + b.HasKey(e => e.Id); + + b.Property(e => e.Id) + .UseIdentityColumn(); + }); + + modelBuilder.Entity(b => + { + b.HasKey(e => e.Id); + }); + } + } +} diff --git a/Tests/LinqToDB.EntityFrameworkCore.SqlServer.Tests/ToolsTests.cs b/Tests/LinqToDB.EntityFrameworkCore.SqlServer.Tests/ToolsTests.cs index bd7b606..9387df9 100644 --- a/Tests/LinqToDB.EntityFrameworkCore.SqlServer.Tests/ToolsTests.cs +++ b/Tests/LinqToDB.EntityFrameworkCore.SqlServer.Tests/ToolsTests.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +using FluentAssertions; using LinqToDB.Data; using LinqToDB.EntityFrameworkCore.BaseTests; using LinqToDB.EntityFrameworkCore.BaseTests.Models.Northwind; @@ -76,29 +77,7 @@ private NorthwindContext CreateContext(bool enableFilter) //ctx.Database.EnsureDeleted(); if (ctx.Database.EnsureCreated()) { - - - SetIdentityInsert(ctx, "[dbo].[Employees]", true); - SetIdentityInsert(ctx, "[dbo].[Categories]", true); - SetIdentityInsert(ctx, "[dbo].[Orders]", true); - SetIdentityInsert(ctx, "[dbo].[Products]", true); - SetIdentityInsert(ctx, "[dbo].[Shippers]", true); - SetIdentityInsert(ctx, "[dbo].[Suppliers]", true); - - try - { - NorthwindData.Seed(ctx); - } - finally - { - SetIdentityInsert(ctx, "[dbo].[Employees]", false); - SetIdentityInsert(ctx, "[dbo].[Categories]", false); - SetIdentityInsert(ctx, "[dbo].[Orders]", false); - SetIdentityInsert(ctx, "[dbo].[Products]", false); - SetIdentityInsert(ctx, "[dbo].[Shippers]", false); - SetIdentityInsert(ctx, "[dbo].[Suppliers]", false); - } - + NorthwindData.Seed(ctx); } return ctx; } @@ -371,26 +350,6 @@ public void TestAssociations() } - [Test] - public void TestIdentityColumn() - { - using (var ctx = CreateContext(false)) - { - var dependencies = ctx.GetService(); - var mappingSource = ctx.GetService(); - var converters = ctx.GetService(); - var dLogger = ctx.GetService>(); - var ms = LinqToDBForEFTools.GetMappingSchema(ctx.Model, converters, dependencies, mappingSource, dLogger); - - var identity = ms.GetAttribute(typeof(Customer), - MemberHelper.MemberOf(c => c.CustomerId)); - - //TODO: - //Assert.NotNull(identity); - //Assert.AreEqual(true, identity.IsIdentity); - } - } - [Repeat(2)] [Test] public void TestGlobalQueryFilters([Values(true, false)] bool enableFilter) From d46822543c2e85b1dace8ea2d9dd1341fdca34d2 Mon Sep 17 00:00:00 2001 From: Svyatoslav Danyliv Date: Thu, 3 Jun 2021 21:15:13 +0300 Subject: [PATCH 3/4] Updated lin2db to 3.4.0. --- .../linq2db.EntityFrameworkCore.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/LinqToDB.EntityFrameworkCore/linq2db.EntityFrameworkCore.csproj b/Source/LinqToDB.EntityFrameworkCore/linq2db.EntityFrameworkCore.csproj index 7dbdaf9..6ae42cf 100644 --- a/Source/LinqToDB.EntityFrameworkCore/linq2db.EntityFrameworkCore.csproj +++ b/Source/LinqToDB.EntityFrameworkCore/linq2db.EntityFrameworkCore.csproj @@ -17,7 +17,7 @@ - + From 2c94b48c427694c9e8cf0900a0b032a19d09cbc3 Mon Sep 17 00:00:00 2001 From: Svyatoslav Danyliv Date: Thu, 3 Jun 2021 21:45:30 +0300 Subject: [PATCH 4/4] Increased version to 5.3.0 --- Build/linq2db.Default.props | 2 +- NuGet/linq2db.EntityFrameworkCore.nuspec | 2 +- azure-pipelines.yml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Build/linq2db.Default.props b/Build/linq2db.Default.props index 878a1f4..b433034 100644 --- a/Build/linq2db.Default.props +++ b/Build/linq2db.Default.props @@ -1,6 +1,6 @@  - 5.2.1 + 5.3.0 Svyatoslav Danyliv, Igor Tkachev, Dmitry Lukashenko, Ilya Chudin Linq to DB diff --git a/NuGet/linq2db.EntityFrameworkCore.nuspec b/NuGet/linq2db.EntityFrameworkCore.nuspec index d988332..3c58d58 100644 --- a/NuGet/linq2db.EntityFrameworkCore.nuspec +++ b/NuGet/linq2db.EntityFrameworkCore.nuspec @@ -16,7 +16,7 @@ - + diff --git a/azure-pipelines.yml b/azure-pipelines.yml index a0b5673..fb1b1aa 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -1,8 +1,8 @@ variables: solution: 'linq2db.EFCore.sln' build_configuration: 'Release' - assemblyVersion: 5.2.1 - nugetVersion: 5.2.1 + assemblyVersion: 5.3.0 + nugetVersion: 5.3.0 artifact_nugets: 'nugets' # build on commits to important branches (master + release branches):