Created
January 4, 2017 12:36
-
-
Save lbargaoanu/dd272fcdead462b0588f48e4a5a92575 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
void Main() | |
{ | |
Mapper.Initialize(x => | |
{ | |
x.CreateMap<Origin, OriginContract>(); | |
x.CreateMap<OriginContract, Origin>(); | |
x.CreateMap<State, StateContract>(); | |
x.CreateMap<StateContract, State>(); | |
}); | |
using (TestContext context = new TestContext()) | |
{ | |
context.Origins.ProjectTo<OriginContract>().Dump(); | |
} | |
} | |
public class DatabaseInitializer : DropCreateDatabaseAlways<TestContext> | |
{ | |
protected override void Seed(TestContext context) | |
{ | |
context.Origins.Add(new Origin { Name ="AppName1", State = new State { Name = "AppState1"}}); | |
context.Origins.Add(new Origin { Name ="AppName2", State = new State { Name = "AppState2"}}); | |
base.Seed(context); | |
} | |
} | |
public class TestContext : System.Data.Entity.DbContext | |
{ | |
public TestContext() : base(@"Server=(localdb)\MSSQLLocalDB;Integrated Security=true;Initial Catalog = TestContext;") | |
{ | |
//Database.Log = s=>Debug.WriteLine(s); | |
Database.SetInitializer<TestContext>(new DatabaseInitializer()); | |
} | |
public DbSet<Origin> Origins { get; set; } | |
public DbSet<State> States { get; set; } | |
} | |
[Table("template.Origin")] | |
public partial class Origin | |
{ | |
public int OriginId { get; set; } | |
public string Code { get; set; } | |
public string Name { get; set; } | |
public string City { get; set; } | |
public int StateId { get; set; } | |
public virtual State State { get; set; } | |
} | |
[Table("template.State")] | |
public partial class State | |
{ | |
public int StateId { get; set; } | |
public string Abbreviation { get; set; } | |
public string Name { get; set; } | |
} | |
public class OriginContract | |
{ | |
public int OriginId { get; set; } | |
public string Code { get; set; } | |
public string Name { get; set; } | |
public string City { get; set; } | |
public int StateId { get; set; } | |
public StateContract State { get; set; } | |
} | |
public class StateContract | |
{ | |
public int StateId { get; set; } | |
public string Abbreviation { get; set; } | |
public string Name { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment