Created
          March 5, 2012 22:09 
        
      - 
      
- 
        Save clausjoergensen/1981492 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
    
  
  
    
  | class Test<PageType> : DbContext | |
| where PageType : class | |
| { | |
| private Dictionary<Type, PageType> callbacks = new Dictionary<Type, PageType>(); | |
| protected override void OnModelCreating(DbModelBuilder modelBuilder) | |
| { | |
| base.OnModelCreating(modelBuilder); | |
| foreach (var type in callbacks.Keys) | |
| { | |
| var entity = modelBuilder.Entity<Page>(); | |
| var callback = this.GetType().GetMethod("InternalMap").MakeGenericMethod(type); | |
| entity.GetType().InvokeMember("Map", BindingFlags.InvokeMethod, null, entity, new object[] { type }); | |
| } | |
| } | |
| private void InternalMap<TEntityType>(EntityMappingConfiguration<TEntityType> m) | |
| { | |
| m.Requires("PageTypeId").HasValue(callbacks[typeof(TEntityType)].PageTypeId); | |
| m.MapInheritedProperties(); | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment