0

Have a database table with more than 1000 records (eg city). Is there any method or Exporter, what would translate it in code-first.

PS To create through code- first small plate is still possible, but large (100,500) for a long time ....

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
WOLF
  • 1

1 Answers1

0

You can easily reverse engineer the whole model into pure POCO model, aka Code-Firs model, with a few clicks. You need to install MySQL connector .NET from here. Be sure to read this first in order not to get into pesky exceptions. There are some mishaps with different versions of MySQL server password store model and mysql connector but they are resolvable.

When you are finished installing :

  1. Open your project.
  2. Right-click your csproj
  3. Add new item
  4. Choose "Data" from the left pane.
  5. Choose "ADO.NET Entity Data Model"
  6. then in the wizard choose "Code first from database"
  7. then if you did the installation of MySQL Connector as prescribed you will be able to connect to your server, select all the table you want and VS will create a model for you. Be sure to install the latest MySQL connector because only there every MySQL type is supported. Some previous versions does not support everything and exception will be thrown.

When you are done a pure code entity model class which derives from DbContext will be created.

Community
  • 1
  • 1
Ognyan Dimitrov
  • 6,026
  • 1
  • 48
  • 70
  • Yes, it works (I also watched this http://msdn.microsoft.com/ru-ru/data/jj200620) ...   Is there any way you take the seeds from the base? Automatically enumeration to write long .... – WOLF Dec 01 '14 at 10:10
  • how to take a enumeration to the database created in Code first//// – WOLF Dec 01 '14 at 10:14
  • db.Set().AddRange(myEnumerable).SaveChanges(); – Ognyan Dimitrov Dec 01 '14 at 11:51
  • that's not what I wanted .... I would like to record from the database converted to enum – WOLF Dec 01 '14 at 12:44
  • Sorry, but I do not understand what "to record from the database converted to enum" actually means. Do you mean to transform a single row from the DB to IEnumerable? – Ognyan Dimitrov Dec 01 '14 at 12:46
  • But if you do it you will need reflection or other type inference in order to work with the properties of the entity. You do not need to do this. You can cast your query in anonymous type or other type. You can enumerate only the result of the query and not the elements of a single row. (At least without reflection of course). What are you trying to achieve? Probably you have to formulate it in another question because it goes off topic to the current question. – Ognyan Dimitrov Dec 01 '14 at 13:04
  • Sorry... I understand everything. Come on simple. I have a database table with 500 rows. I need to convert or translate (I do not know how to say) this table in C # code. So what would the database rows moved into enumeration. For Example:   public enum Cheats      {          New York,          Los Angeles,          Chicago,          Houston,        Philadelphia ....      }; At the moment I realized the only model code first ... – WOLF Dec 01 '14 at 13:16
  • Edit your post and paste some of your code. Paste part of your entity model (DbContext). Because otherwise I will continue to try guess it wrong. – Ognyan Dimitrov Dec 01 '14 at 13:17