0

I created a C# data layer using Entity Framework 6 via the Code First From Database wizard which defined all of the C# classes which represent their respective tables.

There was a table that I missed and I'm looking for a way to generate another class to represent the table.

Is there a way to have this class created after the initial wizard has already been run?

2
  • With Code First, you can definitely do it. If you want more specific help, your question will need to be more specific and include the relevant code. Commented Jul 17, 2015 at 15:33
  • @sstan The scenario is that the database was already in existence, and I want an additional generated class to represent another table in the database (which is huge and not managed by me). Commented Jul 17, 2015 at 15:42

1 Answer 1

1

The reverse engineer tool is meant to be used once in code first. Once it has been used you would just add the class that represents the table along with the other entities. If you are adding tables in the database after you have used the wizzard then you are not truely using code first. Just add a POCO class to the entities folder the tool generated and model it after the others. Once you have done that you use the package manager console to add-migration which aligns it back with your schema, next you use update-database to push the changes back to SQL Server.

Sign up to request clarification or add additional context in comments.

4 Comments

The database is readonly, I am only trying to create a class representation of a table that was not added with the wizard.
@Jason In that case then the only thing you can do is remove the folder it created and run it again. Or you can just use an .EDMX file and use a database first representation of the database. Then you can just right click on the diagram and hit "update from database". The code first reverse engineer tool is designed to be used one time as a starting point for using code first on an existing database.
Thanks Stephen. If you edit your answer to specificically say, no you cannot do this with Code First From DataBase somewhere in the answer (for other viewers), I can thankfully accept your answer!
@Jason. Yes you are correct that this cannot be done with code first from a database. Using a EDMX file is a plausable work around in this case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.