4

I need to crate Composite Key dynamically with anonymous type like follow.

modelBuilder.Entity<TEntity>().HasKey(**x => new { x.Property1, x.Property2}**); 

I managed to crate dynamically for single key. But I've no idea how to crate for composite key. I've spent enough time on google for this solution, but I couldn't find one. Any help would appreciate.

Soe
  • 91
  • 1
  • 7
  • Related: [How to create LINQ Expression Tree with anonymous type in it](http://stackoverflow.com/questions/606104/how-to-create-linq-expression-tree-with-anonymous-type-in-it) – dtb Sep 05 '11 at 07:36

1 Answers1

0

I think this should work:

modelBuilder.Entity<TEntity>().HasKey(x => x.Property1).HasKey(x => x.Property2);
Ivo
  • 8,172
  • 5
  • 27
  • 42