using System.Threading.Tasks;
using Detached.Mappers.EntityFramework;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
public static async Task Main()
TestDbContext dbContext = new TestDbContext();
await dbContext.Database.EnsureCreatedAsync();
dbContext.Map<User>(new User { Id = 1, Name = "this User was mapped from an Entity" });
dbContext.Map<User>(new UserDTO { Id = 2, Name = "this User was mapped from a DTO" });
dbContext.Map<User>(new { Id = 3, Name = "this User was mapped from an Anonymous Type" });
dbContext.Map<User>(new Dictionary<string, object> { { "Id", 4 }, { "Name", "this User was mapped from a Dictionary" } });
await dbContext.SaveChangesAsync();
Console.WriteLine("Getting Started");
Console.WriteLine("----------------------------------------------------------------------------------------");
foreach (User persistedUser in dbContext.Users)
Console.WriteLine($"Id: {persistedUser.Id}, Name = '{persistedUser.Name}'");
class TestDbContext : DbContext
static SqliteConnection _connection;
_connection = new SqliteConnection($"DataSource=file:{Guid.NewGuid()}?mode=memory&cache=shared");
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
optionsBuilder.UseSqlite(_connection).UseMapping();
public DbSet<User> Users { get; set; }
public int Id { get; set; }
public string Name { get; set; }
public int Id { get; set; }
public string Name { get; set; }