0

I need to create composite key with fluent API dynamically according to database schema. I google for the solution but can't find any. Any suggestion how to do that?

Soe
  • 91
  • 1
  • 7
  • What you mean by dynamically? Mapping is static. – Ladislav Mrnka Aug 26 '11 at 09:07
  • I have crated plain POCO with data annotation. and I do the configuration with Fluent API. but I want to read pk or uk from the database and map it. I only know to do like this. HasKey(p => new { p.COMMODITY_ID }); Is there any way I can do it dynamically? – Soe Aug 26 '11 at 09:12
  • Are you looking for reverse engineering feature from [EF Power Tools](http://blogs.msdn.com/b/adonet/archive/2011/05/18/ef-power-tools-ctp1-released.aspx)? Otherwise your question doesn't make sense. – Ladislav Mrnka Aug 26 '11 at 09:18
  • Correction, I meant "I have created plain POCO without data annotation". Yes, I mean reverse engineering. But my database is evolving. I don't want to tie those configuration with my POCO and I don't want to create it mapping everytime database change. I'm looking for a way to read the meta from database and dynamically attach it. – Soe Aug 26 '11 at 09:34

1 Answers1

0

Evolving database = evolving classes = evolving mapping. There is no automation for this because your classes don't have to be 1:1 image of your database and it is up to mapping to describe how they relate.

Even doing 1:1 automation is project itself. It is quite complex task and it will take you much longer to built that then simply evolving your mapping manually. Also there is no reason to do that because it already exists in EF Power Tools.

If you still want to do that go to SQL Books online and learn how SQL persists information about tables, columns, relations, constraints, etc. Then learn how to either use T4 templates or CodeDom to generate classes. Use these two set of information to get description of database and create mapping accordingly (it will be much harder if you would like to do that mapping to existing classes btw.).

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670