Skip to content
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 @@ -84,6 +84,6 @@ public override IEnumerable<IAnnotation> For(IProperty property)
}

private static bool HasConverter(IProperty property)
=> property.GetTypeMapping().Converter != null;
=> property.FindMapping()?.Converter != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,9 @@ protected virtual Task ExecuteAsync(IServiceProvider services, Action<MigrationB
return executor.ExecuteNonQueryAsync(commandList, connection);
}

[ConditionalFact]
public abstract void Can_diff_against_2_2_model();

protected virtual void BuildFirstMigration(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
Expand Down
101 changes: 101 additions & 0 deletions test/EFCore.SqlServer.FunctionalTests/MigrationsSqlServerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal;
using Microsoft.EntityFrameworkCore.Storage;
Expand Down Expand Up @@ -493,5 +496,103 @@ protected override void Up(MigrationBuilder migrationBuilder)
{
}
}

public override void Can_diff_against_2_2_model()
{
using (var context = new ModelSnapshot22.BloggingContext())
{
var snapshot = new BloggingContextModelSnapshot22();
var sourceModel = snapshot.Model;
var targetModel = context.Model;

var modelDiffer = context.GetService<IMigrationsModelDiffer>();
var operations = modelDiffer.GetDifferences(sourceModel, targetModel);

Assert.Equal(0, operations.Count);
}
}

public class BloggingContextModelSnapshot22 : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "2.2.4-servicing-10062")
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);

modelBuilder.Entity("ModelSnapshot22.Blog", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);

b.Property<string>("Name");

b.HasKey("Id");

b.ToTable("Blogs");
});

modelBuilder.Entity("ModelSnapshot22.Post", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);

b.Property<int?>("BlogId");

b.Property<string>("Content");

b.Property<DateTime>("EditDate");

b.Property<string>("Title");

b.HasKey("Id");

b.HasIndex("BlogId");

b.ToTable("Post");
});

modelBuilder.Entity("ModelSnapshot22.Post", b =>
{
b.HasOne("ModelSnapshot22.Blog", "Blog")
.WithMany("Posts")
.HasForeignKey("BlogId");
});
#pragma warning restore 612, 618
}
}
}
}

namespace ModelSnapshot22
{
public class Blog
{
public int Id { get; set; }
public string Name { get; set; }

public ICollection<Post> Posts { get; set; }
}

public class Post
{
public int Id { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public DateTime EditDate { get; set; }

public Blog Blog { get; set; }
}

public class BloggingContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=Test;ConnectRetryCount=0");

public DbSet<Blog> Blogs { get; set; }
}
}
100 changes: 100 additions & 0 deletions test/EFCore.Sqlite.FunctionalTests/MigrationsSqliteTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System;
using System.Collections.Generic;
using System.Data.Common;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Migrations.Operations;
Expand Down Expand Up @@ -298,5 +300,103 @@ FROM sqlite_master

return builder.ToString();
}

public override void Can_diff_against_2_2_model()
{
using (var context = new ModelSnapshot22.BloggingContext())
{
var snapshot = new BloggingContextModelSnapshot22();
var sourceModel = snapshot.Model;
var targetModel = context.Model;

var modelDiffer = context.GetService<IMigrationsModelDiffer>();
var operations = modelDiffer.GetDifferences(sourceModel, targetModel);

Assert.Equal(0, operations.Count);
}
}

public class BloggingContextModelSnapshot22 : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "2.2.4-servicing-10062");

modelBuilder.Entity(
"ModelSnapshot22.Blog", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();

b.Property<string>("Name");

b.HasKey("Id");

b.ToTable("Blogs");
});

modelBuilder.Entity(
"ModelSnapshot22.Post", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();

b.Property<int?>("BlogId");

b.Property<string>("Content");

b.Property<DateTime>("EditDate");

b.Property<string>("Title");

b.HasKey("Id");

b.HasIndex("BlogId");

b.ToTable("Post");
});

modelBuilder.Entity(
"ModelSnapshot22.Post", b =>
{
b.HasOne("ModelSnapshot22.Blog", "Blog")
.WithMany("Posts")
.HasForeignKey("BlogId");
});
#pragma warning restore 612, 618
}
}
}
}

namespace ModelSnapshot22
{
public class Blog
{
public int Id { get; set; }
public string Name { get; set; }

public ICollection<Post> Posts { get; set; }
}

public class Post
{
public int Id { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public DateTime EditDate { get; set; }

public Blog Blog { get; set; }
}

public class BloggingContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder.UseSqlite("DataSource=Test.db");

public DbSet<Blog> Blogs { get; set; }
}
}