1

For a few reasons I would like to use FluentAPI to overriding the EF conventions for the generated field definitions. By default, EF6 creates data annotations for all of the generated classes.

Is there an automated way to convert these annotations to FluentAPI, or get EF to create FluentAPI definitions instead of using data annotations?

Bandito
  • 330
  • 4
  • 15

1 Answers1

0

I finally got this resolved and working. (I was using EF6 with MySQL 5.1.76 and VS2015 update 3).

I installed the modified powertools VSIX to run with VS2015 by following this: http://thedatafarm.com/data-access/installing-ef-power-tools-into-vs2015/ (thanks @Steve). However, selecting the option to 'Reverse Engineer Code First' failed for the following reasons:

  1. Any references to MySQL versions found in C:\Windows\Microsoft.NET\Framework\vx.x.xx\config\machine.config need to match the version of mySQL.Data.Entity.EF6 in your project references. (your text editor needs to be run in admin mode to save the file).

  2. Error: MySQL - Entity : The value for column 'IsPrimaryKey' in table 'TableDetails' is DBNull - This was resolved by following the accepted answer to that post.

  3. Error: Visual Studio 2015 Update 2 breaks EF reverse code engineer vsix - This was resolved by resetting the target framework to 4.5.1

Now I can select 'Reverse Engineer Code First' option and it runs without error, and my model is created successfully with FluentAPI mappings just as I wanted.

Community
  • 1
  • 1
Bandito
  • 330
  • 4
  • 15
  • As a follow up to this, Entity Framework Core defaults to using FluentAPI mappings and has some other nice new features that are not necessarily going to be ported over to EF6 so, this may be a good way to go if you have the choice. – Bandito Sep 23 '16 at 09:55