├── AutoMapping.Pattern1 ├── appsettings.json ├── Data │ ├── Entities │ │ ├── Category.cs │ │ ├── BaseEntity.cs │ │ └── Post.cs │ └── ApplicationDbContext.cs ├── appsettings.Development.json ├── Models │ ├── CategoryDto.cs │ ├── PostDto.cs │ └── ComplexPostDto.cs ├── AutoMapping.Pattern1.csproj ├── Program.cs ├── Properties │ └── launchSettings.json ├── Infrastructure │ ├── BaseDto.cs │ └── AutoMapperConfigurations.cs ├── Startup.cs └── Controllers │ └── PostsController.cs ├── AutoMapping.Pattern2 ├── appsettings.json ├── Data │ ├── Entities │ │ ├── Category.cs │ │ ├── BaseEntity.cs │ │ └── Post.cs │ └── ApplicationDbContext.cs ├── Infrastructure │ ├── IHaveCustomMapping.cs │ ├── CustomMappingProfile.cs │ ├── AutoMapperConfiguration.cs │ └── BaseDto.cs ├── appsettings.Development.json ├── Models │ ├── CategoryDto.cs │ ├── PostDto.cs │ └── ComplexPostDto.cs ├── AutoMapping.Pattern2.csproj ├── Program.cs ├── Properties │ └── launchSettings.json ├── Startup.cs └── Controllers │ └── PostsController.cs ├── README.md ├── AutoMapping.sln ├── .gitattributes └── .gitignore /AutoMapping.Pattern1/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Warning" 5 | } 6 | }, 7 | "AllowedHosts": "*" 8 | } 9 | -------------------------------------------------------------------------------- /AutoMapping.Pattern2/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Warning" 5 | } 6 | }, 7 | "AllowedHosts": "*" 8 | } 9 | -------------------------------------------------------------------------------- /AutoMapping.Pattern1/Data/Entities/Category.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapping.Pattern1.Data.Entities 2 | { 3 | public class Category : BaseEntity 4 | { 5 | public string Name { get; set; } 6 | public string Description { get; set; } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /AutoMapping.Pattern2/Data/Entities/Category.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapping.Pattern2.Data.Entities 2 | { 3 | public class Category : BaseEntity 4 | { 5 | public string Name { get; set; } 6 | public string Description { get; set; } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /AutoMapping.Pattern2/Infrastructure/IHaveCustomMapping.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | 3 | namespace AutoMapping.Pattern2.Infrastructure 4 | { 5 | public interface IHaveCustomMapping 6 | { 7 | void CreateMappings(Profile profile); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /AutoMapping.Pattern1/Data/Entities/BaseEntity.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapping.Pattern1.Data.Entities 2 | { 3 | public abstract class BaseEntity 4 | { 5 | public TKey Id { get; set; } 6 | } 7 | 8 | public abstract class BaseEntity : BaseEntity 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /AutoMapping.Pattern2/Data/Entities/BaseEntity.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapping.Pattern2.Data.Entities 2 | { 3 | public abstract class BaseEntity 4 | { 5 | public TKey Id { get; set; } 6 | } 7 | 8 | public abstract class BaseEntity : BaseEntity 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # auto-mapping 2 | Auto mapping with AutoMapper and Reflection in ASP.NET Core 3 | 4 | #### Introduction 5 | * [https://www.dotnettips.info/post/2983](https://www.dotnettips.info/post/2983) (Part 1) 6 | * [https://www.dotnettips.info/post/2988](https://www.dotnettips.info/post/2988) (Part 2) 7 | -------------------------------------------------------------------------------- /AutoMapping.Pattern1/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "ConnectionStrings": { 3 | "SqlServer": "Data Source=.;Initial Catalog=AutoMappingDb;Integrated Security=true" 4 | }, 5 | "Logging": { 6 | "LogLevel": { 7 | "Default": "Debug", 8 | "System": "Information", 9 | "Microsoft": "Information" 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /AutoMapping.Pattern2/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "ConnectionStrings": { 3 | "SqlServer": "Data Source=.;Initial Catalog=AutoMappingDb;Integrated Security=true" 4 | }, 5 | "Logging": { 6 | "LogLevel": { 7 | "Default": "Debug", 8 | "System": "Information", 9 | "Microsoft": "Information" 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /AutoMapping.Pattern1/Data/Entities/Post.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapping.Pattern1.Data.Entities 2 | { 3 | public class Post : BaseEntity 4 | { 5 | public string Title { get; set; } 6 | public string Text { get; set; } 7 | public int CatgeoryId { get; set; } 8 | 9 | public Category Category { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /AutoMapping.Pattern2/Data/Entities/Post.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapping.Pattern2.Data.Entities 2 | { 3 | public class Post : BaseEntity 4 | { 5 | public string Title { get; set; } 6 | public string Text { get; set; } 7 | public int CategoryId { get; set; } 8 | 9 | public Category Category { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /AutoMapping.Pattern1/Models/CategoryDto.cs: -------------------------------------------------------------------------------- 1 | using AutoMapping.Pattern1.Data.Entities; 2 | using AutoMapping.Pattern1.Infrastructure; 3 | 4 | namespace AutoMapping.Pattern1.Models 5 | { 6 | public class CategoryDto : BaseDto 7 | { 8 | public int Name { get; set; } 9 | public string Description { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /AutoMapping.Pattern2/Models/CategoryDto.cs: -------------------------------------------------------------------------------- 1 | using AutoMapping.Pattern2.Data.Entities; 2 | using AutoMapping.Pattern2.Infrastructure; 3 | 4 | namespace AutoMapping.Pattern2.Models 5 | { 6 | public class CategoryDto : BaseDto 7 | { 8 | public string Name { get; set; } 9 | public string Description { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /AutoMapping.Pattern2/Infrastructure/CustomMappingProfile.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using System.Collections.Generic; 3 | 4 | namespace AutoMapping.Pattern2.Infrastructure 5 | { 6 | public class CustomMappingProfile : Profile 7 | { 8 | public CustomMappingProfile(IEnumerable haveCustomMappings) 9 | { 10 | foreach (var item in haveCustomMappings) 11 | item.CreateMappings(this); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /AutoMapping.Pattern1/Models/PostDto.cs: -------------------------------------------------------------------------------- 1 | using AutoMapping.Pattern1.Data.Entities; 2 | using AutoMapping.Pattern1.Infrastructure; 3 | 4 | namespace AutoMapping.Pattern1.Models 5 | { 6 | public class PostDto : BaseDto 7 | { 8 | public string Title { get; set; } 9 | public string Text { get; set; } 10 | public int CategoryId { get; set; } 11 | 12 | public string CategoryName { get; set; } //=> Category.Name 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /AutoMapping.Pattern1/AutoMapping.Pattern1.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /AutoMapping.Pattern2/AutoMapping.Pattern2.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /AutoMapping.Pattern1/Data/ApplicationDbContext.cs: -------------------------------------------------------------------------------- 1 | using AutoMapping.Pattern1.Data.Entities; 2 | using Microsoft.EntityFrameworkCore; 3 | 4 | namespace AutoMapping.Pattern1.Data 5 | { 6 | public class ApplicationDbContext : DbContext 7 | { 8 | public DbSet Posts { get; set; } 9 | public DbSet Categories { get; set; } 10 | 11 | public ApplicationDbContext(DbContextOptions options) 12 | : base(options) 13 | { 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /AutoMapping.Pattern2/Data/ApplicationDbContext.cs: -------------------------------------------------------------------------------- 1 | using AutoMapping.Pattern2.Data.Entities; 2 | using Microsoft.EntityFrameworkCore; 3 | 4 | namespace AutoMapping.Pattern2.Data 5 | { 6 | public class ApplicationDbContext : DbContext 7 | { 8 | public DbSet Posts { get; set; } 9 | public DbSet Categories { get; set; } 10 | 11 | public ApplicationDbContext(DbContextOptions options) 12 | : base(options) 13 | { 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /AutoMapping.Pattern1/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace AutoMapping.Pattern1 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | CreateWebHostBuilder(args).Build().Run(); 18 | } 19 | 20 | public static IWebHostBuilder CreateWebHostBuilder(string[] args) => 21 | WebHost.CreateDefaultBuilder(args) 22 | .UseStartup(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /AutoMapping.Pattern2/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace AutoMapping.Pattern2 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | CreateWebHostBuilder(args).Build().Run(); 18 | } 19 | 20 | public static IWebHostBuilder CreateWebHostBuilder(string[] args) => 21 | WebHost.CreateDefaultBuilder(args) 22 | .UseStartup(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /AutoMapping.Pattern1/Models/ComplexPostDto.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using AutoMapping.Pattern1.Data.Entities; 3 | using AutoMapping.Pattern1.Infrastructure; 4 | 5 | namespace AutoMapping.Pattern1.Models 6 | { 7 | public class ComplexPostDto : BaseDto 8 | { 9 | public string Title { get; set; } 10 | 11 | //Ignore property from any mapping (even from ComplexPostDto to Post or inverse) and could be set value manually 12 | [IgnoreMap] 13 | public string Text { get; set; } 14 | 15 | public int CategoryId { get; set; } 16 | 17 | public string CategoryName { get; set; } //=> mapped from Category.Name 18 | 19 | public CategoryDto Category { get; set; } //=> mapped from Post.Category 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /AutoMapping.Pattern2/Models/PostDto.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using AutoMapping.Pattern2.Data.Entities; 3 | using AutoMapping.Pattern2.Infrastructure; 4 | 5 | namespace AutoMapping.Pattern2.Models 6 | { 7 | public class PostDto : BaseDto 8 | { 9 | public string Title { get; set; } 10 | public string Text { get; set; } 11 | public int CategoryId { get; set; } 12 | 13 | public string CategoryName { get; set; } //=> Category.Name 14 | public string FullTitle { get; set; } //=> custom mapping for "Title (Category.Name)" 15 | 16 | public override void CustomMappings(IMappingExpression mapping) 17 | { 18 | mapping 19 | .ReverseMap() 20 | .ForMember( 21 | dest => dest.FullTitle, 22 | config => config.MapFrom(src => $"{src.Title} ({src.Category.Name})")); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /AutoMapping.Pattern1/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:5942", 8 | "sslPort": 0 9 | } 10 | }, 11 | "profiles": { 12 | "IIS Express": { 13 | "commandName": "IISExpress", 14 | "launchBrowser": true, 15 | "launchUrl": "api/posts", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "AutoMapping.Pattern1": { 21 | "commandName": "Project", 22 | "launchBrowser": true, 23 | "launchUrl": "api/posts", 24 | "applicationUrl": "http://localhost:5000", 25 | "environmentVariables": { 26 | "ASPNETCORE_ENVIRONMENT": "Development" 27 | } 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /AutoMapping.Pattern2/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:5947", 8 | "sslPort": 0 9 | } 10 | }, 11 | "profiles": { 12 | "IIS Express": { 13 | "commandName": "IISExpress", 14 | "launchBrowser": true, 15 | "launchUrl": "api/posts", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "AutoMapping.Pattern2": { 21 | "commandName": "Project", 22 | "launchBrowser": true, 23 | "launchUrl": "api/posts", 24 | "applicationUrl": "http://localhost:5000", 25 | "environmentVariables": { 26 | "ASPNETCORE_ENVIRONMENT": "Development" 27 | } 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /AutoMapping.Pattern2/Models/ComplexPostDto.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using AutoMapping.Pattern2.Data.Entities; 3 | using AutoMapping.Pattern2.Infrastructure; 4 | 5 | namespace AutoMapping.Pattern2.Models 6 | { 7 | public class ComplexPostDto : BaseDto 8 | { 9 | public string Title { get; set; } 10 | 11 | //Ignore property from any mapping (even from ComplexPostDto to Post or inverse) and could be set value manually 12 | [IgnoreMap] 13 | public string Text { get; set; } 14 | 15 | public int CategoryId { get; set; } 16 | 17 | public string CategoryName { get; set; } //=> mapped from Category.Name 18 | public string FullTitle { get; set; } //=> custom mapping for "Title (Category.Name)" 19 | 20 | public CategoryDto Category { get; set; } //=> mapped from Post.Category 21 | 22 | public override void CustomMappings(IMappingExpression mapping) 23 | { 24 | mapping 25 | .ReverseMap() 26 | .ForMember( 27 | dest => dest.FullTitle, 28 | config => config.MapFrom(src => $"{src.Title} ({src.Category.Name})")); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /AutoMapping.Pattern1/Infrastructure/BaseDto.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using AutoMapping.Pattern1.Data.Entities; 3 | using System.ComponentModel.DataAnnotations; 4 | 5 | namespace AutoMapping.Pattern1.Infrastructure 6 | { 7 | public abstract class BaseDto 8 | where TEntity : BaseEntity 9 | { 10 | [Display(Name = "ردیف")] 11 | public TKey Id { get; set; } 12 | 13 | /// 14 | /// Maps this dto to a new entity object. 15 | /// 16 | public TEntity ToEntity() 17 | { 18 | return Mapper.Map(CastToDerivedClass(this)); 19 | } 20 | 21 | /// 22 | /// Maps this dto to an exist entity object. 23 | /// 24 | public TEntity ToEntity(TEntity entity) 25 | { 26 | return Mapper.Map(CastToDerivedClass(this), entity); 27 | } 28 | 29 | /// 30 | /// Maps the specified entity to a new dto object. 31 | /// 32 | public static TDto FromEntity(TEntity model) 33 | { 34 | return Mapper.Map(model); 35 | } 36 | 37 | protected TDto CastToDerivedClass(BaseDto baseInstance) 38 | { 39 | return Mapper.Map(baseInstance); 40 | } 41 | } 42 | 43 | public abstract class BaseDto : BaseDto 44 | where TDto : class, new() 45 | where TEntity : BaseEntity, new() 46 | { 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /AutoMapping.Pattern2/Infrastructure/AutoMapperConfiguration.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using System; 3 | using System.Linq; 4 | using System.Reflection; 5 | 6 | namespace AutoMapping.Pattern2.Infrastructure 7 | { 8 | public static class AutoMapperConfiguration 9 | { 10 | public static void InitializeAutoMapper() 11 | { 12 | Mapper.Initialize(config => 13 | { 14 | config.AddCustomMappingProfile(); 15 | }); 16 | 17 | //Compile mapping after configuration to boost map speed 18 | Mapper.Configuration.CompileMappings(); 19 | } 20 | 21 | public static void AddCustomMappingProfile(this IMapperConfigurationExpression config) 22 | { 23 | config.AddCustomMappingProfile(Assembly.GetEntryAssembly()); 24 | } 25 | 26 | public static void AddCustomMappingProfile(this IMapperConfigurationExpression config, params Assembly[] assemblies) 27 | { 28 | var allTypes = assemblies.SelectMany(a => a.ExportedTypes); 29 | 30 | //Find all classes that implement IHaveCustomMapping inteface and create new instance of each 31 | var list = allTypes.Where(type => type.IsClass && !type.IsAbstract && 32 | type.GetInterfaces().Contains(typeof(IHaveCustomMapping))) 33 | .Select(type => (IHaveCustomMapping)Activator.CreateInstance(type)); 34 | 35 | //Create a new automapper Profile for this list to create mapping then add to the config 36 | var profile = new CustomMappingProfile(list); 37 | config.AddProfile(profile); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /AutoMapping.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28010.2050 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoMapping.Pattern1", "AutoMapping.Pattern1\AutoMapping.Pattern1.csproj", "{9F0EFD3C-153D-44FB-ACEC-BC5F18B433E9}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoMapping.Pattern2", "AutoMapping.Pattern2\AutoMapping.Pattern2.csproj", "{05E4E31E-6317-47E5-AE6A-882D6CFBE8AD}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {9F0EFD3C-153D-44FB-ACEC-BC5F18B433E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {9F0EFD3C-153D-44FB-ACEC-BC5F18B433E9}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {9F0EFD3C-153D-44FB-ACEC-BC5F18B433E9}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {9F0EFD3C-153D-44FB-ACEC-BC5F18B433E9}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {05E4E31E-6317-47E5-AE6A-882D6CFBE8AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {05E4E31E-6317-47E5-AE6A-882D6CFBE8AD}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {05E4E31E-6317-47E5-AE6A-882D6CFBE8AD}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {05E4E31E-6317-47E5-AE6A-882D6CFBE8AD}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {068D3E0A-57C6-406B-B4F1-E85DA8303A80} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /AutoMapping.Pattern1/Startup.cs: -------------------------------------------------------------------------------- 1 | using AutoMapping.Pattern1.Data; 2 | using AutoMapping.Pattern1.Infrastructure; 3 | using Microsoft.AspNetCore.Builder; 4 | using Microsoft.AspNetCore.Hosting; 5 | using Microsoft.AspNetCore.Mvc; 6 | using Microsoft.EntityFrameworkCore; 7 | using Microsoft.EntityFrameworkCore.Diagnostics; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.DependencyInjection; 10 | 11 | namespace AutoMapping.Pattern1 12 | { 13 | public class Startup 14 | { 15 | public Startup(IConfiguration configuration) 16 | { 17 | Configuration = configuration; 18 | 19 | AutoMapperConfiguration.InitializeAutoMapper(); 20 | } 21 | 22 | public IConfiguration Configuration { get; } 23 | 24 | // This method gets called by the runtime. Use this method to add services to the container. 25 | public void ConfigureServices(IServiceCollection services) 26 | { 27 | services.AddDbContext(options => 28 | { 29 | options 30 | .UseSqlServer(Configuration.GetConnectionString("SqlServer")) 31 | //Disbale ClientEvaluation (throw exception when use this) 32 | .ConfigureWarnings(warning => warning.Throw(RelationalEventId.QueryClientEvaluationWarning)); 33 | }); 34 | 35 | services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); 36 | } 37 | 38 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 39 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 40 | { 41 | if (env.IsDevelopment()) 42 | { 43 | app.UseDeveloperExceptionPage(); 44 | } 45 | 46 | app.UseMvc(); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /AutoMapping.Pattern2/Startup.cs: -------------------------------------------------------------------------------- 1 | using AutoMapping.Pattern2.Data; 2 | using AutoMapping.Pattern2.Infrastructure; 3 | using Microsoft.AspNetCore.Builder; 4 | using Microsoft.AspNetCore.Hosting; 5 | using Microsoft.AspNetCore.Mvc; 6 | using Microsoft.EntityFrameworkCore; 7 | using Microsoft.EntityFrameworkCore.Diagnostics; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.DependencyInjection; 10 | 11 | namespace AutoMapping.Pattern2 12 | { 13 | public class Startup 14 | { 15 | public Startup(IConfiguration configuration) 16 | { 17 | Configuration = configuration; 18 | 19 | AutoMapperConfiguration.InitializeAutoMapper(); 20 | } 21 | 22 | public IConfiguration Configuration { get; } 23 | 24 | // This method gets called by the runtime. Use this method to add services to the container. 25 | public void ConfigureServices(IServiceCollection services) 26 | { 27 | services.AddDbContext(options => 28 | { 29 | options 30 | .UseSqlServer(Configuration.GetConnectionString("SqlServer")) 31 | //Disbale ClientEvaluation (throw exception when use this) 32 | .ConfigureWarnings(warning => warning.Throw(RelationalEventId.QueryClientEvaluationWarning)); 33 | }); 34 | 35 | services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); 36 | } 37 | 38 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 39 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 40 | { 41 | if (env.IsDevelopment()) 42 | { 43 | app.UseDeveloperExceptionPage(); 44 | } 45 | 46 | app.UseMvc(); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /AutoMapping.Pattern2/Infrastructure/BaseDto.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using AutoMapping.Pattern2.Data.Entities; 3 | using System.ComponentModel.DataAnnotations; 4 | 5 | namespace AutoMapping.Pattern2.Infrastructure 6 | { 7 | public abstract class BaseDto : IHaveCustomMapping 8 | where TEntity : BaseEntity 9 | { 10 | [Display(Name = "ردیف")] 11 | public TKey Id { get; set; } 12 | 13 | /// 14 | /// Maps this dto to a new entity object. 15 | /// 16 | public TEntity ToEntity() 17 | { 18 | return Mapper.Map(CastToDerivedClass(this)); 19 | } 20 | 21 | /// 22 | /// Maps this dto to an exist entity object. 23 | /// 24 | public TEntity ToEntity(TEntity entity) 25 | { 26 | return Mapper.Map(CastToDerivedClass(this), entity); 27 | } 28 | 29 | /// 30 | /// Maps the specified entity to a new dto object. 31 | /// 32 | public static TDto FromEntity(TEntity model) 33 | { 34 | return Mapper.Map(model); 35 | } 36 | 37 | protected TDto CastToDerivedClass(BaseDto baseInstance) 38 | { 39 | return Mapper.Map(baseInstance); 40 | } 41 | 42 | //Get automapper Profile then create mapping and ignore unmapped properties 43 | public void CreateMappings(Profile profile) 44 | { 45 | var mappingExpression = profile.CreateMap(); 46 | 47 | var dtoType = typeof(TDto); 48 | var entityType = typeof(TEntity); 49 | 50 | //Ignore mapping to any property of source (like Post.Categroy) that dose not contains in destination (like PostDto) 51 | //To prevent from wrong mapping. for example in mapping of "PostDto -> Post", automapper create a new instance for Category (with null catgeoryName) because we have CategoryName property that has null value 52 | foreach (var property in entityType.GetProperties()) 53 | { 54 | if (dtoType.GetProperty(property.Name) == null) 55 | mappingExpression.ForMember(property.Name, opt => opt.Ignore()); 56 | } 57 | 58 | //Pass mapping expressin to customize mapping in concrete class 59 | CustomMappings(mappingExpression); 60 | } 61 | 62 | //Concrete class can override this method to customize mapping 63 | public virtual void CustomMappings(IMappingExpression mapping) 64 | { 65 | } 66 | } 67 | 68 | public abstract class BaseDto : BaseDto 69 | where TEntity : BaseEntity 70 | { 71 | 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /AutoMapping.Pattern1/Infrastructure/AutoMapperConfigurations.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Reflection; 6 | 7 | namespace AutoMapping.Pattern1.Infrastructure 8 | { 9 | public static class AutoMapperConfiguration 10 | { 11 | public static void InitializeAutoMapper() 12 | { 13 | Mapper.Initialize(configuration => 14 | { 15 | configuration.ConfigureAutoMapperForDto(); 16 | }); 17 | 18 | //Compile mapping after configuration to boost map speed 19 | Mapper.Configuration.CompileMappings(); 20 | } 21 | 22 | public static void ConfigureAutoMapperForDto(this IMapperConfigurationExpression config) 23 | { 24 | config.ConfigureAutoMapperForDto(Assembly.GetEntryAssembly()); 25 | } 26 | 27 | public static void ConfigureAutoMapperForDto(this IMapperConfigurationExpression config, params Assembly[] assemblies) 28 | { 29 | var dtoTypes = GetDtoTypes(assemblies); 30 | 31 | var mappingTypes = dtoTypes 32 | .Select(type => 33 | { 34 | var arguments = type.BaseType.GetGenericArguments(); 35 | return new 36 | { 37 | DtoType = arguments[0], 38 | EntityType = arguments[1] 39 | }; 40 | }).ToList(); 41 | 42 | foreach (var mappingType in mappingTypes) 43 | config.CreateMappingAndIgnoreUnmappedProperties(mappingType.EntityType, mappingType.DtoType); 44 | } 45 | 46 | public static void CreateMappingAndIgnoreUnmappedProperties(this IMapperConfigurationExpression config, Type entityType, Type dtoType) 47 | { 48 | var mappingExpression = config.CreateMap(entityType, dtoType).ReverseMap(); 49 | 50 | //Ignore mapping to any property of source (like Post.Categroy) that dose not contains in destination (like PostDto) 51 | //To prevent from wrong mapping. for example in mapping of "PostDto -> Post", automapper create a new instance for Category (with null catgeoryName) because we have CategoryName property that has null value 52 | foreach (var property in entityType.GetProperties()) 53 | { 54 | if (dtoType.GetProperty(property.Name) == null) 55 | mappingExpression.ForMember(property.Name, opt => opt.Ignore()); 56 | } 57 | } 58 | 59 | public static IEnumerable GetDtoTypes(params Assembly[] assemblies) 60 | { 61 | var allTypes = assemblies.SelectMany(a => a.ExportedTypes); 62 | 63 | var dtoTypes = allTypes.Where(type => 64 | type.IsClass && !type.IsAbstract && type.BaseType != null && type.BaseType.IsGenericType && 65 | (type.BaseType.GetGenericTypeDefinition() == typeof(BaseDto<,>) || 66 | type.BaseType.GetGenericTypeDefinition() == typeof(BaseDto<,,>))); 67 | 68 | return dtoTypes; 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /AutoMapping.Pattern2/Controllers/PostsController.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Dynamic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using AutoMapper.QueryableExtensions; 6 | using AutoMapping.Pattern2.Data; 7 | using AutoMapping.Pattern2.Models; 8 | using Microsoft.AspNetCore.Mvc; 9 | using Microsoft.EntityFrameworkCore; 10 | 11 | namespace AutoMapping.Pattern2.Controllers 12 | { 13 | [Route("api/[controller]")] 14 | [ApiController] 15 | public class PostsController : ControllerBase 16 | { 17 | private readonly ApplicationDbContext _applicationDbContext; 18 | 19 | public PostsController(ApplicationDbContext applicationDbContext) 20 | { 21 | _applicationDbContext = applicationDbContext; 22 | } 23 | 24 | // GET api/posts 25 | [HttpGet] 26 | public async Task>> Get() 27 | { 28 | var list = 29 | //We use AsNotracking because this is a read only select 30 | //ProjectTo method select only needed properties (of PostDto) not all properties 31 | //Also select only needed property of navigations (like Post.Category.Name) not all unlike Include 32 | //This ability called "Projection" 33 | await _applicationDbContext.Posts.AsNoTracking().ProjectTo() 34 | //We can also use Where on IQuerable 35 | .Where(p => p.Title.Contains("test") || p.CategoryName.Contains("test")) 36 | .ToListAsync(); 37 | 38 | return list; 39 | } 40 | 41 | // GET api/posts/5 42 | [HttpGet("{id}")] 43 | public async Task> Get(long id) 44 | { 45 | var postDto = await _applicationDbContext.Posts.AsNoTracking().ProjectTo() 46 | .SingleOrDefaultAsync(p => p.Id == id); 47 | 48 | ////Another example : without using ProjectTo, use BaseDto.FromEntity instead 49 | //var post = await _applicationDbContext.Posts.AsNoTracking().Include(p => p.Category) 50 | // .SingleOrDefaultAsync(p => p.Id == id); 51 | ////Create a PostDto from Post with mapping properties 52 | //var postDto = PostDto.FromEntity(post); 53 | 54 | return postDto; 55 | } 56 | 57 | // GET api/posts/GetById/5 58 | [HttpGet("[action]/{id}")] 59 | public async Task> GetById(long id) 60 | { 61 | //Another example : without using ProjectTo, use BaseDto.FromEntity instead 62 | var post = await _applicationDbContext.Posts.AsNoTracking().Include(p => p.Category) 63 | .SingleOrDefaultAsync(p => p.Id == id); 64 | 65 | //Create a PostDto from Post with mapping properties 66 | var postDto = PostDto.FromEntity(post); 67 | 68 | return postDto; 69 | } 70 | 71 | // POST api/posts 72 | [HttpPost] 73 | public async Task Post(PostDto postDto) 74 | { 75 | //Create a new Post with mapped properties from PostDto 76 | var post = postDto.ToEntity(); 77 | 78 | await _applicationDbContext.Posts.AddAsync(post); 79 | await _applicationDbContext.SaveChangesAsync(); 80 | 81 | return Ok(); 82 | } 83 | 84 | // PUT api/posts/5 85 | [HttpPut("{id}")] 86 | public async Task Put(long id, PostDto postDto) 87 | { 88 | var post = await _applicationDbContext.Posts.FindAsync(id); 89 | 90 | //Change properties values of a finded Post by id, from PostDto 91 | var updatePost = postDto.ToEntity(post); 92 | 93 | _applicationDbContext.Posts.Update(updatePost); 94 | await _applicationDbContext.SaveChangesAsync(); 95 | 96 | return Ok(); 97 | } 98 | 99 | // DELETE api/posts/5 100 | [HttpDelete("{id}")] 101 | public async Task Delete(long id) 102 | { 103 | var post = await _applicationDbContext.Posts.FindAsync(id); 104 | 105 | _applicationDbContext.Posts.Remove(post); 106 | await _applicationDbContext.SaveChangesAsync(); 107 | 108 | return Ok(); 109 | } 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /AutoMapping.Pattern1/Controllers/PostsController.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using System.Threading.Tasks; 4 | using AutoMapper.QueryableExtensions; 5 | using AutoMapping.Pattern1.Data; 6 | using AutoMapping.Pattern1.Data.Entities; 7 | using AutoMapping.Pattern1.Models; 8 | using Microsoft.AspNetCore.Mvc; 9 | using Microsoft.EntityFrameworkCore; 10 | 11 | namespace AutoMapping.Pattern1.Controllers 12 | { 13 | [Route("api/[controller]")] 14 | [ApiController] 15 | public class PostsController : ControllerBase 16 | { 17 | private readonly ApplicationDbContext _applicationDbContext; 18 | 19 | public PostsController(ApplicationDbContext applicationDbContext) 20 | { 21 | _applicationDbContext = applicationDbContext; 22 | } 23 | 24 | // GET api/posts 25 | [HttpGet] 26 | public async Task>> Get() 27 | { 28 | var list = 29 | //We use AsNotracking because this is a read only select 30 | //ProjectTo method select only needed properties (of PostDto) not all properties 31 | //Also select only needed property of navigations (like Post.Category.Name) not all unlike Include 32 | //This ability called "Projection" 33 | await _applicationDbContext.Posts.AsNoTracking().ProjectTo() 34 | //We can also use Where on IQuerable 35 | .Where(p => p.Title.Contains("test") || p.CategoryName.Contains("test")) 36 | .ToListAsync(); 37 | 38 | return list; 39 | } 40 | 41 | // GET api/posts/5 42 | [HttpGet("{id}")] 43 | public async Task> Get(long id) 44 | { 45 | var postDto = await _applicationDbContext.Posts.AsNoTracking().ProjectTo() 46 | .SingleOrDefaultAsync(p => p.Id == id); 47 | 48 | ////Another example : without using ProjectTo, use BaseDto.FromEntity instead 49 | //var post = await _applicationDbContext.Posts.AsNoTracking().Include(p => p.Category) 50 | // .SingleOrDefaultAsync(p => p.Id == id); 51 | ////Create a PostDto from Post with mapping properties 52 | //var postDto = PostDto.FromEntity(post); 53 | 54 | return postDto; 55 | } 56 | 57 | // GET api/posts/GetById/5 58 | [HttpGet("[action]/{id}")] 59 | public async Task> GetById(long id) 60 | { 61 | //Another example : without using ProjectTo, use BaseDto.FromEntity instead 62 | var post = await _applicationDbContext.Posts.AsNoTracking().Include(p => p.Category) 63 | .SingleOrDefaultAsync(p => p.Id == id); 64 | 65 | //Create a PostDto from Post with mapping properties 66 | var postDto = PostDto.FromEntity(post); 67 | 68 | return postDto; 69 | } 70 | 71 | // POST api/posts 72 | [HttpPost] 73 | public async Task Post(PostDto postDto) 74 | { 75 | //Create a new Post with mapped properties from PostDto 76 | var post = postDto.ToEntity(); 77 | 78 | await _applicationDbContext.Posts.AddAsync(post); 79 | await _applicationDbContext.SaveChangesAsync(); 80 | 81 | return Ok(); 82 | } 83 | 84 | // PUT api/posts/5 85 | [HttpPut("{id}")] 86 | public async Task Put(long id, PostDto postDto) 87 | { 88 | var post = await _applicationDbContext.Posts.FindAsync(id); 89 | 90 | 91 | //Change properties values of a finded Post by id, from PostDto 92 | var updatePost = postDto.ToEntity(post); 93 | 94 | _applicationDbContext.Posts.Update(updatePost); 95 | await _applicationDbContext.SaveChangesAsync(); 96 | 97 | return Ok(); 98 | } 99 | 100 | // DELETE api/posts/5 101 | [HttpDelete("{id}")] 102 | public async Task Delete(long id) 103 | { 104 | var post = await _applicationDbContext.Posts.FindAsync(id); 105 | 106 | _applicationDbContext.Posts.Remove(post); 107 | await _applicationDbContext.SaveChangesAsync(); 108 | 109 | return Ok(); 110 | } 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | project.fragment.lock.json 46 | artifacts/ 47 | 48 | *_i.c 49 | *_p.c 50 | *_i.h 51 | *.ilk 52 | *.meta 53 | *.obj 54 | *.pch 55 | *.pdb 56 | *.pgc 57 | *.pgd 58 | *.rsp 59 | *.sbr 60 | *.tlb 61 | *.tli 62 | *.tlh 63 | *.tmp 64 | *.tmp_proj 65 | *.log 66 | *.vspscc 67 | *.vssscc 68 | .builds 69 | *.pidb 70 | *.svclog 71 | *.scc 72 | 73 | # Chutzpah Test files 74 | _Chutzpah* 75 | 76 | # Visual C++ cache files 77 | ipch/ 78 | *.aps 79 | *.ncb 80 | *.opendb 81 | *.opensdf 82 | *.sdf 83 | *.cachefile 84 | *.VC.db 85 | *.VC.VC.opendb 86 | 87 | # Visual Studio profiler 88 | *.psess 89 | *.vsp 90 | *.vspx 91 | *.sap 92 | 93 | # TFS 2012 Local Workspace 94 | $tf/ 95 | 96 | # Guidance Automation Toolkit 97 | *.gpState 98 | 99 | # ReSharper is a .NET coding add-in 100 | _ReSharper*/ 101 | *.[Rr]e[Ss]harper 102 | *.DotSettings.user 103 | 104 | # JustCode is a .NET coding add-in 105 | .JustCode 106 | 107 | # TeamCity is a build add-in 108 | _TeamCity* 109 | 110 | # DotCover is a Code Coverage Tool 111 | *.dotCover 112 | 113 | # NCrunch 114 | _NCrunch_* 115 | .*crunch*.local.xml 116 | nCrunchTemp_* 117 | 118 | # MightyMoose 119 | *.mm.* 120 | AutoTest.Net/ 121 | 122 | # Web workbench (sass) 123 | .sass-cache/ 124 | 125 | # Installshield output folder 126 | [Ee]xpress/ 127 | 128 | # DocProject is a documentation generator add-in 129 | DocProject/buildhelp/ 130 | DocProject/Help/*.HxT 131 | DocProject/Help/*.HxC 132 | DocProject/Help/*.hhc 133 | DocProject/Help/*.hhk 134 | DocProject/Help/*.hhp 135 | DocProject/Help/Html2 136 | DocProject/Help/html 137 | 138 | # Click-Once directory 139 | publish/ 140 | 141 | # Publish Web Output 142 | *.[Pp]ublish.xml 143 | *.azurePubxml 144 | # TODO: Comment the next line if you want to checkin your web deploy settings 145 | # but database connection strings (with potential passwords) will be unencrypted 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 150 | # checkin your Azure Web App publish settings, but sensitive information contained 151 | # in these scripts will be unencrypted 152 | PublishScripts/ 153 | 154 | # NuGet Packages 155 | *.nupkg 156 | # The packages folder can be ignored because of Package Restore 157 | **/packages/* 158 | # except build/, which is used as an MSBuild target. 159 | !**/packages/build/ 160 | # Uncomment if necessary however generally it will be regenerated when needed 161 | #!**/packages/repositories.config 162 | # NuGet v3's project.json files produces more ignoreable files 163 | *.nuget.props 164 | *.nuget.targets 165 | 166 | # Microsoft Azure Build Output 167 | csx/ 168 | *.build.csdef 169 | 170 | # Microsoft Azure Emulator 171 | ecf/ 172 | rcf/ 173 | 174 | # Windows Store app package directories and files 175 | AppPackages/ 176 | BundleArtifacts/ 177 | Package.StoreAssociation.xml 178 | _pkginfo.txt 179 | 180 | # Visual Studio cache files 181 | # files ending in .cache can be ignored 182 | *.[Cc]ache 183 | # but keep track of directories ending in .cache 184 | !*.[Cc]ache/ 185 | 186 | # Others 187 | ClientBin/ 188 | ~$* 189 | *~ 190 | *.dbmdl 191 | *.dbproj.schemaview 192 | *.jfm 193 | *.pfx 194 | *.publishsettings 195 | node_modules/ 196 | orleans.codegen.cs 197 | 198 | # Since there are multiple workflows, uncomment next line to ignore bower_components 199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 200 | #bower_components/ 201 | 202 | # RIA/Silverlight projects 203 | Generated_Code/ 204 | 205 | # Backup & report files from converting an old project file 206 | # to a newer Visual Studio version. Backup files are not needed, 207 | # because we have git ;-) 208 | _UpgradeReport_Files/ 209 | Backup*/ 210 | UpgradeLog*.XML 211 | UpgradeLog*.htm 212 | 213 | # SQL Server files 214 | *.mdf 215 | *.ldf 216 | 217 | # Business Intelligence projects 218 | *.rdl.data 219 | *.bim.layout 220 | *.bim_*.settings 221 | 222 | # Microsoft Fakes 223 | FakesAssemblies/ 224 | 225 | # GhostDoc plugin setting file 226 | *.GhostDoc.xml 227 | 228 | # Node.js Tools for Visual Studio 229 | .ntvs_analysis.dat 230 | 231 | # Visual Studio 6 build log 232 | *.plg 233 | 234 | # Visual Studio 6 workspace options file 235 | *.opt 236 | 237 | # Visual Studio LightSwitch build output 238 | **/*.HTMLClient/GeneratedArtifacts 239 | **/*.DesktopClient/GeneratedArtifacts 240 | **/*.DesktopClient/ModelManifest.xml 241 | **/*.Server/GeneratedArtifacts 242 | **/*.Server/ModelManifest.xml 243 | _Pvt_Extensions 244 | 245 | # Paket dependency manager 246 | .paket/paket.exe 247 | paket-files/ 248 | 249 | # FAKE - F# Make 250 | .fake/ 251 | 252 | # JetBrains Rider 253 | .idea/ 254 | *.sln.iml 255 | 256 | # CodeRush 257 | .cr/ 258 | 259 | # Python Tools for Visual Studio (PTVS) 260 | __pycache__/ 261 | *.pyc --------------------------------------------------------------------------------