From c217e058f3a1ab71f81631784bc81b59ed5276c3 Mon Sep 17 00:00:00 2001 From: Omar Muscatello <7016897+OmarMuscatello@users.noreply.github.com> Date: Thu, 14 Sep 2017 16:37:24 +0200 Subject: [PATCH] Added support for Guid. Added DateTime and Guid fileds in example projects. Added migrations in example projects. --- .../AppDbContext.cs | 16 --- .../20170914140401_Init.Designer.cs | 39 ++++++ .../Migrations/20170914140401_Init.cs | 34 +++++ .../20170914142601_BirthDate.Designer.cs | 41 ++++++ .../Migrations/20170914142601_BirthDate.cs | 24 ++++ .../20170914142632_GlobalId.Designer.cs | 43 ++++++ .../Migrations/20170914142632_GlobalId.cs | 24 ++++ .../Migrations/AppDbContextModelSnapshot.cs | 42 ++++++ .../SimplePatch.Examples.Core.DAL/Person.cs | 7 +- .../SimplePatch.Examples.Core.DAL.csproj | 1 + .../SimplePatch.Examples.Core.WebAPI.csproj | 2 +- .../201709141340179_BirthDate.Designer.cs | 29 ++++ .../Migrations/201709141340179_BirthDate.cs | 18 +++ .../Migrations/201709141340179_BirthDate.resx | 126 ++++++++++++++++++ .../201709141340313_GlobalId.Designer.cs | 29 ++++ .../Migrations/201709141340313_GlobalId.cs | 18 +++ .../Migrations/201709141340313_GlobalId.resx | 126 ++++++++++++++++++ .../Person.cs | 7 +- .../SimplePatch.Examples.FullNET.DAL.csproj | 14 ++ ...SimplePatch.Examples.FullNET.WebAPI.csproj | 4 +- .../packages.config | 2 +- src/SimplePatch/Delta.cs | 19 ++- src/SimplePatch/DeltaConfig.cs | 10 +- src/SimplePatch/SimplePatch.csproj | 6 +- 24 files changed, 651 insertions(+), 30 deletions(-) create mode 100644 examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.DAL/Migrations/20170914140401_Init.Designer.cs create mode 100644 examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.DAL/Migrations/20170914140401_Init.cs create mode 100644 examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.DAL/Migrations/20170914142601_BirthDate.Designer.cs create mode 100644 examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.DAL/Migrations/20170914142601_BirthDate.cs create mode 100644 examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.DAL/Migrations/20170914142632_GlobalId.Designer.cs create mode 100644 examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.DAL/Migrations/20170914142632_GlobalId.cs create mode 100644 examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.DAL/Migrations/AppDbContextModelSnapshot.cs create mode 100644 examples/SimplePatch.Examples.FullNET/SimplePatch.Examples.FullNET.DAL/Migrations/201709141340179_BirthDate.Designer.cs create mode 100644 examples/SimplePatch.Examples.FullNET/SimplePatch.Examples.FullNET.DAL/Migrations/201709141340179_BirthDate.cs create mode 100644 examples/SimplePatch.Examples.FullNET/SimplePatch.Examples.FullNET.DAL/Migrations/201709141340179_BirthDate.resx create mode 100644 examples/SimplePatch.Examples.FullNET/SimplePatch.Examples.FullNET.DAL/Migrations/201709141340313_GlobalId.Designer.cs create mode 100644 examples/SimplePatch.Examples.FullNET/SimplePatch.Examples.FullNET.DAL/Migrations/201709141340313_GlobalId.cs create mode 100644 examples/SimplePatch.Examples.FullNET/SimplePatch.Examples.FullNET.DAL/Migrations/201709141340313_GlobalId.resx diff --git a/examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.DAL/AppDbContext.cs b/examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.DAL/AppDbContext.cs index b7cc828..8064df1 100644 --- a/examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.DAL/AppDbContext.cs +++ b/examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.DAL/AppDbContext.cs @@ -19,22 +19,6 @@ public AppDbContext(DbContextOptions options) : base(options) private void Init() { Database.EnsureCreated(); - - if (People.CountAsync().Result == 0) - { - People.AddRange( - new Person() { Name = "Name 1", Surname = "Surname 1", Age = 21 }, - new Person() { Name = "Name 2", Surname = "Surname 2", Age = 22 }, - new Person() { Name = "Name 3", Surname = "Surname 3", Age = 23 }, - new Person() { Name = "Name 4", Surname = "Surname 4", Age = 24 }, - new Person() { Name = "Name 5", Surname = "Surname 5", Age = 25 }, - new Person() { Name = "Name 6", Surname = "Surname 6", Age = 26 }, - new Person() { Name = "Name 7", Surname = "Surname 7", Age = 27 }, - new Person() { Name = "Name 8", Surname = "Surname 8", Age = 28 }, - new Person() { Name = "Name 9", Surname = "Surname 9", Age = 29 } - ); - SaveChanges(); - } } diff --git a/examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.DAL/Migrations/20170914140401_Init.Designer.cs b/examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.DAL/Migrations/20170914140401_Init.Designer.cs new file mode 100644 index 0000000..ac60be0 --- /dev/null +++ b/examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.DAL/Migrations/20170914140401_Init.Designer.cs @@ -0,0 +1,39 @@ +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using SimplePatch.Examples.Core.DAL; + +namespace SimplePatch.Examples.Core.DAL.Migrations +{ + [DbContext(typeof(AppDbContext))] + [Migration("20170914140401_Init")] + partial class Init + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { + modelBuilder + .HasAnnotation("ProductVersion", "1.1.2") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("SimplePatch.Examples.Core.DAL.Person", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Age"); + + b.Property("Name") + .IsRequired(); + + b.Property("Surname") + .IsRequired(); + + b.HasKey("Id"); + + b.ToTable("People"); + }); + } + } +} diff --git a/examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.DAL/Migrations/20170914140401_Init.cs b/examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.DAL/Migrations/20170914140401_Init.cs new file mode 100644 index 0000000..6b9ee74 --- /dev/null +++ b/examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.DAL/Migrations/20170914140401_Init.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Metadata; + +namespace SimplePatch.Examples.Core.DAL.Migrations +{ + public partial class Init : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "People", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), + Age = table.Column(nullable: false), + Name = table.Column(nullable: false), + Surname = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_People", x => x.Id); + }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "People"); + } + } +} diff --git a/examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.DAL/Migrations/20170914142601_BirthDate.Designer.cs b/examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.DAL/Migrations/20170914142601_BirthDate.Designer.cs new file mode 100644 index 0000000..8bfb99d --- /dev/null +++ b/examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.DAL/Migrations/20170914142601_BirthDate.Designer.cs @@ -0,0 +1,41 @@ +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using SimplePatch.Examples.Core.DAL; + +namespace SimplePatch.Examples.Core.DAL.Migrations +{ + [DbContext(typeof(AppDbContext))] + [Migration("20170914142601_BirthDate")] + partial class BirthDate + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { + modelBuilder + .HasAnnotation("ProductVersion", "1.1.2") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("SimplePatch.Examples.Core.DAL.Person", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Age"); + + b.Property("BirthDate"); + + b.Property("Name") + .IsRequired(); + + b.Property("Surname") + .IsRequired(); + + b.HasKey("Id"); + + b.ToTable("People"); + }); + } + } +} diff --git a/examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.DAL/Migrations/20170914142601_BirthDate.cs b/examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.DAL/Migrations/20170914142601_BirthDate.cs new file mode 100644 index 0000000..c94f6c0 --- /dev/null +++ b/examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.DAL/Migrations/20170914142601_BirthDate.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace SimplePatch.Examples.Core.DAL.Migrations +{ + public partial class BirthDate : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "BirthDate", + table: "People", + nullable: true); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "BirthDate", + table: "People"); + } + } +} diff --git a/examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.DAL/Migrations/20170914142632_GlobalId.Designer.cs b/examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.DAL/Migrations/20170914142632_GlobalId.Designer.cs new file mode 100644 index 0000000..d933aaa --- /dev/null +++ b/examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.DAL/Migrations/20170914142632_GlobalId.Designer.cs @@ -0,0 +1,43 @@ +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using SimplePatch.Examples.Core.DAL; + +namespace SimplePatch.Examples.Core.DAL.Migrations +{ + [DbContext(typeof(AppDbContext))] + [Migration("20170914142632_GlobalId")] + partial class GlobalId + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { + modelBuilder + .HasAnnotation("ProductVersion", "1.1.2") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("SimplePatch.Examples.Core.DAL.Person", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Age"); + + b.Property("BirthDate"); + + b.Property("GlobalId"); + + b.Property("Name") + .IsRequired(); + + b.Property("Surname") + .IsRequired(); + + b.HasKey("Id"); + + b.ToTable("People"); + }); + } + } +} diff --git a/examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.DAL/Migrations/20170914142632_GlobalId.cs b/examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.DAL/Migrations/20170914142632_GlobalId.cs new file mode 100644 index 0000000..6991a85 --- /dev/null +++ b/examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.DAL/Migrations/20170914142632_GlobalId.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace SimplePatch.Examples.Core.DAL.Migrations +{ + public partial class GlobalId : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "GlobalId", + table: "People", + nullable: true); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "GlobalId", + table: "People"); + } + } +} diff --git a/examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.DAL/Migrations/AppDbContextModelSnapshot.cs b/examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.DAL/Migrations/AppDbContextModelSnapshot.cs new file mode 100644 index 0000000..f982fd9 --- /dev/null +++ b/examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.DAL/Migrations/AppDbContextModelSnapshot.cs @@ -0,0 +1,42 @@ +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using SimplePatch.Examples.Core.DAL; + +namespace SimplePatch.Examples.Core.DAL.Migrations +{ + [DbContext(typeof(AppDbContext))] + partial class AppDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { + modelBuilder + .HasAnnotation("ProductVersion", "1.1.2") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("SimplePatch.Examples.Core.DAL.Person", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Age"); + + b.Property("BirthDate"); + + b.Property("GlobalId"); + + b.Property("Name") + .IsRequired(); + + b.Property("Surname") + .IsRequired(); + + b.HasKey("Id"); + + b.ToTable("People"); + }); + } + } +} diff --git a/examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.DAL/Person.cs b/examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.DAL/Person.cs index 04c25d9..4dd6e2f 100644 --- a/examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.DAL/Person.cs +++ b/examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.DAL/Person.cs @@ -1,4 +1,5 @@ -using System.ComponentModel.DataAnnotations; +using System; +using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace SimplePatch.Examples.Core.DAL @@ -15,5 +16,9 @@ public class Person public string Surname { get; set; } public int Age { get; set; } + + public DateTime? BirthDate { get; set; } + + public Guid? GlobalId { get; set; } } } \ No newline at end of file diff --git a/examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.DAL/SimplePatch.Examples.Core.DAL.csproj b/examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.DAL/SimplePatch.Examples.Core.DAL.csproj index 1bec717..cff45f6 100644 --- a/examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.DAL/SimplePatch.Examples.Core.DAL.csproj +++ b/examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.DAL/SimplePatch.Examples.Core.DAL.csproj @@ -7,6 +7,7 @@ + diff --git a/examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.WebAPI/SimplePatch.Examples.Core.WebAPI.csproj b/examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.WebAPI/SimplePatch.Examples.Core.WebAPI.csproj index 15dccd3..d287cb7 100644 --- a/examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.WebAPI/SimplePatch.Examples.Core.WebAPI.csproj +++ b/examples/SimplePatch.Examples.Core/SimplePatch.Examples.Core.WebAPI/SimplePatch.Examples.Core.WebAPI.csproj @@ -13,7 +13,7 @@ - + diff --git a/examples/SimplePatch.Examples.FullNET/SimplePatch.Examples.FullNET.DAL/Migrations/201709141340179_BirthDate.Designer.cs b/examples/SimplePatch.Examples.FullNET/SimplePatch.Examples.FullNET.DAL/Migrations/201709141340179_BirthDate.Designer.cs new file mode 100644 index 0000000..0d5d21b --- /dev/null +++ b/examples/SimplePatch.Examples.FullNET/SimplePatch.Examples.FullNET.DAL/Migrations/201709141340179_BirthDate.Designer.cs @@ -0,0 +1,29 @@ +// +namespace SimplePatch.Examples.FullNET.DAL.Migrations +{ + using System.CodeDom.Compiler; + using System.Data.Entity.Migrations; + using System.Data.Entity.Migrations.Infrastructure; + using System.Resources; + + [GeneratedCode("EntityFramework.Migrations", "6.1.3-40302")] + public sealed partial class BirthDate : IMigrationMetadata + { + private readonly ResourceManager Resources = new ResourceManager(typeof(BirthDate)); + + string IMigrationMetadata.Id + { + get { return "201709141340179_BirthDate"; } + } + + string IMigrationMetadata.Source + { + get { return null; } + } + + string IMigrationMetadata.Target + { + get { return Resources.GetString("Target"); } + } + } +} diff --git a/examples/SimplePatch.Examples.FullNET/SimplePatch.Examples.FullNET.DAL/Migrations/201709141340179_BirthDate.cs b/examples/SimplePatch.Examples.FullNET/SimplePatch.Examples.FullNET.DAL/Migrations/201709141340179_BirthDate.cs new file mode 100644 index 0000000..42c2cce --- /dev/null +++ b/examples/SimplePatch.Examples.FullNET/SimplePatch.Examples.FullNET.DAL/Migrations/201709141340179_BirthDate.cs @@ -0,0 +1,18 @@ +namespace SimplePatch.Examples.FullNET.DAL.Migrations +{ + using System; + using System.Data.Entity.Migrations; + + public partial class BirthDate : DbMigration + { + public override void Up() + { + AddColumn("dbo.People", "BirthDate", c => c.DateTime()); + } + + public override void Down() + { + DropColumn("dbo.People", "BirthDate"); + } + } +} diff --git a/examples/SimplePatch.Examples.FullNET/SimplePatch.Examples.FullNET.DAL/Migrations/201709141340179_BirthDate.resx b/examples/SimplePatch.Examples.FullNET/SimplePatch.Examples.FullNET.DAL/Migrations/201709141340179_BirthDate.resx new file mode 100644 index 0000000..d9c7626 --- /dev/null +++ b/examples/SimplePatch.Examples.FullNET/SimplePatch.Examples.FullNET.DAL/Migrations/201709141340179_BirthDate.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + H4sIAAAAAAAEAM1X227jNhB9L7D/IPBpC2TFXF7aQN6F15ciaJwEK+++09LYJpYiVZIK7G/rQz+pv9Ch7pZ8S7JoiwCBRc2cuXDOzOjvP/8KPm0S4T2DNlzJAbnyL4kHMlIxl6sByezywy/k08d3PwWTONl43yq5GyeHmtIMyNra9JZSE60hYcZPeKSVUUvrRyqhLFb0+vLyV3p1RQEhCGJ5XvAlk5YnkD/g40jJCFKbMTFTMQhTnuObMEf1HlgCJmURDEjIk1TAE7PR2p9smHsw/jQT4mEy98fDe+INBWfoVwhiSTwmpbLMote3Xw2EViu5ClM8YGK+TQHllkwYKKO5bcTPDezy2gVGG8UKKsqMVckLAa9uykzRrvqr8k3qTGIuJ5hzu3VR5/kckCe8TgfcNXU7EtqJnU62X0BceKcEL+rawRJzfxfeKBM20zCQkFnNxIX3lC0Ej36H7Vx9BzmQqN32HyPAdzsHePSkVQrabr/AsozqLiYe3dWjXcVaraVTRHwn7c018R7QOFsIqMujlZ3QKg2/gQTNLMQYswUtHQbkCe5Z79hy/ytrWI9INOLN2OYe5MquBwR/Em/KNxBXJ6UHXyVHXqKS1Rns8fC41TDT8j8xPFzBqdweB/jMtV2PMdUVjPs950lHMaBNfferHjuMZRyvrPIqTccLdwgbu4cA2CpKDpgy7F0XC9AQbM0khRVPvMaFov/4FcX2eVr71LQ7WvS7qi/SA40xmLE0xftrNcryxAuLLjn6EL68YSQFBo3Mnr5Re1tbQhqwFXTeomn0dMq1sXhPbMHcBY/ipCe2cwMHsluZ2klytwM0Oa/E3e+y6s/rX13MJp9TDDFBXufRQu1Y3Tt7ivnMYoLpPR1mpESWyENd6ph20TPa+sXJ+Qg1/9sg9eH5ODmd2xj5wfn6LTa3UVrHfayAdm6jWwK0VwOd/t+tqGNs7IrU1mtWdtgXlEw4vbv0qFGIEA+T9MxjR4twaywkvhPwwz/ESHCMtxGYMcmXYGwxIgkuDNedhef/s3xQY2Jx1gbyr0957nJ6co6/cFC1B7t8ZjpaM/0+YZuf3zqs3wbWGsB52G8dvzH+tvn4bZCKzeD147g/M07N22KsHpy3BbHQ2YVCvwsnqyH9ylncZ3lA298xwRgMXzUQ7qtGQuTo04BWMndyqapEY1htjyqRzj3MwDJMPRtqy5cssvg6AmPyLe4bExmKTJIFxHfyMbNpZofGQLIQO+toQI/bzxeOXZ+Dx9Q9mR8RArrJXfU8ys8ZF3Ht97Rfh4cgXKGUlEWvcItFuNW2RnpQ8kygMn1jSEE6ws8BlwMEM48yZM/wGt9wabyHFYu2VbM+DHL6InbTHow5W2mWmBKj0Xff5tR9nH/8B2ZKLznODwAA + + + dbo + + \ No newline at end of file diff --git a/examples/SimplePatch.Examples.FullNET/SimplePatch.Examples.FullNET.DAL/Migrations/201709141340313_GlobalId.Designer.cs b/examples/SimplePatch.Examples.FullNET/SimplePatch.Examples.FullNET.DAL/Migrations/201709141340313_GlobalId.Designer.cs new file mode 100644 index 0000000..daa661d --- /dev/null +++ b/examples/SimplePatch.Examples.FullNET/SimplePatch.Examples.FullNET.DAL/Migrations/201709141340313_GlobalId.Designer.cs @@ -0,0 +1,29 @@ +// +namespace SimplePatch.Examples.FullNET.DAL.Migrations +{ + using System.CodeDom.Compiler; + using System.Data.Entity.Migrations; + using System.Data.Entity.Migrations.Infrastructure; + using System.Resources; + + [GeneratedCode("EntityFramework.Migrations", "6.1.3-40302")] + public sealed partial class GlobalId : IMigrationMetadata + { + private readonly ResourceManager Resources = new ResourceManager(typeof(GlobalId)); + + string IMigrationMetadata.Id + { + get { return "201709141340313_GlobalId"; } + } + + string IMigrationMetadata.Source + { + get { return null; } + } + + string IMigrationMetadata.Target + { + get { return Resources.GetString("Target"); } + } + } +} diff --git a/examples/SimplePatch.Examples.FullNET/SimplePatch.Examples.FullNET.DAL/Migrations/201709141340313_GlobalId.cs b/examples/SimplePatch.Examples.FullNET/SimplePatch.Examples.FullNET.DAL/Migrations/201709141340313_GlobalId.cs new file mode 100644 index 0000000..285a4a3 --- /dev/null +++ b/examples/SimplePatch.Examples.FullNET/SimplePatch.Examples.FullNET.DAL/Migrations/201709141340313_GlobalId.cs @@ -0,0 +1,18 @@ +namespace SimplePatch.Examples.FullNET.DAL.Migrations +{ + using System; + using System.Data.Entity.Migrations; + + public partial class GlobalId : DbMigration + { + public override void Up() + { + AddColumn("dbo.People", "GlobalId", c => c.Guid()); + } + + public override void Down() + { + DropColumn("dbo.People", "GlobalId"); + } + } +} diff --git a/examples/SimplePatch.Examples.FullNET/SimplePatch.Examples.FullNET.DAL/Migrations/201709141340313_GlobalId.resx b/examples/SimplePatch.Examples.FullNET/SimplePatch.Examples.FullNET.DAL/Migrations/201709141340313_GlobalId.resx new file mode 100644 index 0000000..0878515 --- /dev/null +++ b/examples/SimplePatch.Examples.FullNET/SimplePatch.Examples.FullNET.DAL/Migrations/201709141340313_GlobalId.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + H4sIAAAAAAAEAM1Y227jNhB9L9B/EPjUAlkxl5c2kHfhtZ0gaJwEK+++09LYJkqRWpIK7G/rQz+pv9Ch7pZ8TYq2CBBYo5kzF84cjv3XH38Gn9aJ8F5BG67kgFz5l8QDGamYy+WAZHbx4Rfy6eOPPwSTOFl73yq9G6eHltIMyMra9JZSE60gYcZPeKSVUQvrRyqhLFb0+vLyV3p1RQEhCGJ5XvAlk5YnkD/g40jJCFKbMTFVMQhTyvFNmKN6TywBk7IIBiTkSSrghdlo5U/WzD0Y/y4T4mky88fDR+INBWcYVwhiQTwmpbLMYtS3Xw2EViu5DFMUMDHbpIB6CyYMlNncNuqnJnZ57RKjjWEFFWXGquRMwKubslK0a/6mepO6kljLCdbcblzWeT0H5AWP0wF3Xd2OhHZqx4vtFxAX3jHFi7p3sMXc34U3yoTNNAwkZFYzceG9ZHPBo99gM1O/gxxItG7Hjxnguy0Bil60SkHbzRdYlFk9xMSj23a0a1ibtWyKjB+kvbkm3hM6Z3MBdXu0qhNapeEeJGhmIcacLWjpMCAvcM97x5f7X3nDfsRBI96UrR9BLu1qQPAj8e74GuJKUkbwVXKcSzSyOoMdER72GmZa/ieOh0s4VtvDAJ+5tqsxlrqCcZ9nPDlqeC/UnInmaO8z3mmNgDYz0Z8UZCXLOB5zlUmajudOCGu7Y2iQXsq5MWWptqMrQEOw9fQpnBLiNSEUnOVXY7kr0jqmhiJpwZEVl9I9ZBpMWZrimbfItZR4YcGsow/h+SSTFBg0Mju4po629oSjw5bQeYuuMdI7ro3Fs2Vz5ppiFCc9ta0T2FPdytVWkbus0dS8Unefy0k5jfO6mE097zDFBLkgzxbqwGq+7Rnm9xwTTO9gpZESWSL3Mdsh64Jn2vaF5HSEmjPaILXwdJycAtoYueB0+xYDtFFa4tOxGlJoQzXSPlJAO+fabSba66bO7dPtzUNz3VWpvdfz3ZnjoJyp45tTb8gKFeJhiV557AYs3BgLie8U/PC7GAmO+TYKUyb5AowtLmiC68p1Z936/6w+1JhYnLT//Os7Bnc1PbpFnHlNttcK+cp0tGL6p4Stf37vqvA+sNb1n6f93ss/xs82v/wbpGIvOW8ZyCT/ngHPq73goA/jnbco9G+zY5tAceHv3QSKQcXk5wrjL4Ks1oc3bgl91gho+1tZMAbDlw2E+44mIXLj2IBWOg9yoap6Y1rtiCqVznFMwTI8SjbUWH4WWXwdgTH5TvqNiQxVJskc4gf5nNk0s0NjIJmLreU6oIf956vQdszBc+qezD+RAobJXTc+y88ZF3Ed912/r/dBuEYpKQCjwp0c4ZabGulJyROByvKNIQXpWnoGuLYgmHmWIXuFt8SG6+wjLFm0qch/P8jxg9guezDmbKlZYkqMxt790kDdTw0f/wbFiCc/nBAAAA== + + + dbo + + \ No newline at end of file diff --git a/examples/SimplePatch.Examples.FullNET/SimplePatch.Examples.FullNET.DAL/Person.cs b/examples/SimplePatch.Examples.FullNET/SimplePatch.Examples.FullNET.DAL/Person.cs index 7d7af62..e9eb9f4 100644 --- a/examples/SimplePatch.Examples.FullNET/SimplePatch.Examples.FullNET.DAL/Person.cs +++ b/examples/SimplePatch.Examples.FullNET/SimplePatch.Examples.FullNET.DAL/Person.cs @@ -1,4 +1,5 @@ -using System.ComponentModel.DataAnnotations; +using System; +using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace SimplePatch.Examples.FullNET.DAL @@ -15,5 +16,9 @@ public class Person public string Surname { get; set; } public int Age { get; set; } + + public DateTime? BirthDate { get; set; } + + public Guid? GlobalId { get; set; } } } diff --git a/examples/SimplePatch.Examples.FullNET/SimplePatch.Examples.FullNET.DAL/SimplePatch.Examples.FullNET.DAL.csproj b/examples/SimplePatch.Examples.FullNET/SimplePatch.Examples.FullNET.DAL/SimplePatch.Examples.FullNET.DAL.csproj index 859f114..6f9a78f 100644 --- a/examples/SimplePatch.Examples.FullNET/SimplePatch.Examples.FullNET.DAL/SimplePatch.Examples.FullNET.DAL.csproj +++ b/examples/SimplePatch.Examples.FullNET/SimplePatch.Examples.FullNET.DAL/SimplePatch.Examples.FullNET.DAL.csproj @@ -52,6 +52,14 @@ 201708250935300_Init.cs + + + 201709141340179_BirthDate.cs + + + + 201709141340313_GlobalId.cs + @@ -64,6 +72,12 @@ 201708250935300_Init.cs + + 201709141340179_BirthDate.cs + + + 201709141340313_GlobalId.cs + \ No newline at end of file diff --git a/examples/SimplePatch.Examples.FullNET/SimplePatch.Examples.FullNET.WebAPI/SimplePatch.Examples.FullNET.WebAPI.csproj b/examples/SimplePatch.Examples.FullNET/SimplePatch.Examples.FullNET.WebAPI/SimplePatch.Examples.FullNET.WebAPI.csproj index fb9104e..5dd3164 100644 --- a/examples/SimplePatch.Examples.FullNET/SimplePatch.Examples.FullNET.WebAPI/SimplePatch.Examples.FullNET.WebAPI.csproj +++ b/examples/SimplePatch.Examples.FullNET/SimplePatch.Examples.FullNET.WebAPI/SimplePatch.Examples.FullNET.WebAPI.csproj @@ -57,8 +57,8 @@ ..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll - - ..\packages\SimplePatch.1.2.0\lib\net451\SimplePatch.dll + + ..\packages\SimplePatch.1.2.1\lib\net451\SimplePatch.dll diff --git a/examples/SimplePatch.Examples.FullNET/SimplePatch.Examples.FullNET.WebAPI/packages.config b/examples/SimplePatch.Examples.FullNET/SimplePatch.Examples.FullNET.WebAPI/packages.config index 72d276f..0c12064 100644 --- a/examples/SimplePatch.Examples.FullNET/SimplePatch.Examples.FullNET.WebAPI/packages.config +++ b/examples/SimplePatch.Examples.FullNET/SimplePatch.Examples.FullNET.WebAPI/packages.config @@ -11,5 +11,5 @@ - + \ No newline at end of file diff --git a/src/SimplePatch/Delta.cs b/src/SimplePatch/Delta.cs index 116877d..5f77995 100644 --- a/src/SimplePatch/Delta.cs +++ b/src/SimplePatch/Delta.cs @@ -140,7 +140,7 @@ private bool IsPropertyAllowed(string propertyName) /// The modified entity. private TEntity SetPropertiesValue(TEntity entity) { - //Se la cache non contiene la lista delle proprietà per il tipo specificato, aggiungo le proprietà + //If the cache contains the property list for the specified type, set the properties value if (DeltaCache.entityProperties.TryGetValue(typeFullName, out var properties)) { foreach (var prop in properties) @@ -148,9 +148,20 @@ private TEntity SetPropertiesValue(TEntity entity) if (ContainsKey(prop.Name) && !IsExcludedProperty(typeFullName, prop.Name)) { var propertyType = GetTrueType(prop.PropertyType); - var newPropertyvalue = this[prop.Name]; - - prop.SetValue(entity, Convert.ChangeType(newPropertyvalue, propertyType), null); + var newPropertyValue = this[prop.Name]; + + var newPropertyValueType = newPropertyValue.GetType(); + + //Guid from string + if (propertyType == typeof(Guid) && newPropertyValueType == typeof(string)) + { + newPropertyValue = new Guid((string)newPropertyValue); + prop.SetValue(entity, newPropertyValue, null); + } + else + { + prop.SetValue(entity, Convert.ChangeType(newPropertyValue, propertyType), null); + } } } diff --git a/src/SimplePatch/DeltaConfig.cs b/src/SimplePatch/DeltaConfig.cs index c07f632..5a1e2cb 100644 --- a/src/SimplePatch/DeltaConfig.cs +++ b/src/SimplePatch/DeltaConfig.cs @@ -14,7 +14,13 @@ public static void Init(Action config) public sealed class Config { - public void ExcludeProperties(params Expression>[] properties) + /// + /// Sets the properties to exclude when calling . + /// + /// Class in which the property is contained. + /// Properties to exclude when calling + /// + public Config ExcludeProperties(params Expression>[] properties) { var type = typeof(T); @@ -28,6 +34,8 @@ public void ExcludeProperties(params Expression>[] properties string typeFullname = typeof(T).FullName; DeltaCache.excludedProperties.TryAdd(typeFullname, propList.ToArray()); + + return this; } private static MemberExpression GetMemberExpression(Expression> exp) diff --git a/src/SimplePatch/SimplePatch.csproj b/src/SimplePatch/SimplePatch.csproj index 29039f7..2593f41 100644 --- a/src/SimplePatch/SimplePatch.csproj +++ b/src/SimplePatch/SimplePatch.csproj @@ -2,13 +2,13 @@ net451;netstandard1.4 - 1.2.0 + 1.2.1 Omar Muscatello Omar Muscatello - A simple library for using the PATCH method in ASP.NET and ASP.NET Core. + A simple library for partial entity changes in ASP.NET and ASP.NET Core. Copyright (c) Omar Muscatello 2017 https://github.com/OmarMuscatello/SimplePatch/blob/master/LICENSE - Added support for ASP.NET Core. + Added support for Guid. https://github.com/OmarMuscatello/SimplePatch https://github.com/OmarMuscatello/SimplePatch http://raw.github.com/OmarMuscatello/SimplePatch/master/simplepatch-icon.png