Created
September 15, 2017 05:22
-
-
Save lbargaoanu/e97aac49d7b333c515cb89886f22ba11 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void Main(string[] args) | |
{ | |
Mapper.Initialize(cfg => | |
{ | |
cfg.CreateMap<Library, LibraryDto>(); | |
}); | |
using(var context = new TestContext()) | |
{ | |
context.Libraries.ProjectTo<LibraryDto>().Dump(); | |
} | |
} | |
public class DatabaseInitializer : DropCreateDatabaseAlways<TestContext> | |
{ | |
protected override void Seed(TestContext context) | |
{ | |
context.Libraries.AddRange(new[]{new Library { Books = {new Book {}, new Book {}}}}); | |
} | |
} | |
public class TestContext : DbContext | |
{ | |
public TestContext() | |
{ | |
//Database.Log = s=>Debug.WriteLine(s); | |
Database.SetInitializer<TestContext>(new DatabaseInitializer()); | |
} | |
public DbSet<Library> Libraries { get; set; } | |
} | |
public class Library | |
{ | |
public int Id { get; set; } | |
public List<Book> Books { get; set; } | |
public Library() | |
{ | |
Books = new List<Book>(); | |
} | |
} | |
public class Book | |
{ | |
public int Id { get; set; } | |
} | |
public class LibraryDto | |
{ | |
public int Id { get; set; } | |
public int BooksCount { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment