How to update/regenerate CRUD code using OIL package in FuelPHP - fuelphp

I am new to FuelPHP ... I have generated curd code using the following command php oil generate scaffold/crud monkey name:string still_here:bool
it generate migration files, views, controller, and model.. than I use the following command to create database tables php oil refine migrate everything is fine...
but what i need now is to update the table means i want to add more columns to the monkey table in database.... how and what is the reliable way to do this?? so that it will auto update the files as well

There is no built in way of doing this. The only thing you can do is generating migrations or manually creating them and updating your models.
See how to generate migrations: http://fuelphp.com/docs/packages/oil/generate.html#migrations

Related

EF 6 Mix Mode Code First and DB First

Iam using EF 6 with database first .. and every time I update the scheme : all my editings to the edmx file (mainly for defining db built in functions) are lost .. but using code first I can add my dbmodelbuilder calls in a separate file with partial class .. and by that I can also use all the nuget packages that targets code first such as EntityFramework.Functions.
Thanks for helping
You can use Code First from database option when you are creating your ADO.net entity data model. This will give you the code first classes that you can edit.
After creating your model you would need to stick to using the code first model otherwise you will need to regenerate your code-first after every database change...
Download the EF tools here.

Development process for Code First Entity Framework and SQL Server Data Tools Database Projects

I have been using Database First Entity Framework (EDMX) and SQL Server Data Tools Database Projects in combination very successfully - change the schema in the database and 'Update Model from Database' to get them into the EDMX. I see though that Entity Framework 7 will be dropping the EDMX format and I am looking for a new process that will allow me to use Code First in Combination with Database Projects.
Lots of my existing development and deployment processes rely on having a database project that contains the schema. This goes in source control is deployed along with the code and is used to update the production database complete with data migration using pre and post deployment scripts. I would be reluctant to drop it.
I would be keen to split one big EDMX into many smaller models as part of this work. This will mean multiple Code First models referencing the same database.
Assuming that I have an existing database and a database project to go with it - I am thinking that I would start by using the following wizard to create an initial set of entity and context classes - I would do this for each of the models.
Add | New Item... | Visual C# Items | Data | ADO.NET Entity Data Model | Code first from database
My problem is - where do I go from there? How do I handle schema changes? As long as I can get the database schema updated, I can use a schema compare operation to get the changes into the project.
These are the options that I am considering.
Make changes in the database and use the wizard from above to regenerate. I guess that I would need to keep any modifications to the entity and/or context classes in partial classes so that they do not get overwritten. Automating this with a list of tables etc to include would be handy. Powershell or T4 Templates maybe? SqlSharpener (suggested by Keith in comments) looks like it might help here. I would also look at disabling all but the checks for database existence and schema compatibility here, as suggested by Steve Green in the comments.
Make changes in code and use migrations to get these changes applied to the database. From what I understand, not having models map cleanly to database schemas (mine don't) might pose problems. I also see some complaints on the net that migrations do not cover all database object types - this was also my experience when I played around with Code First a while back - unique constraints I think were not covered. Has this improved in Entity Framework 7?
Make changes in the database and then use migrations as a kind of comparison between code and the database. See what the differences are and adjust the code to suit. Keep going until there are no differences.
Make changes manually in both code and the database. Obviously, this is not very appealing.
Which of these would be best? Is there anything that I would need to know before trying to implement it? Are there any other, better options?
So the path that we ended up taking was to create some T4 templates that generate both a DbContext and our entities. We provide the entity T4 a list of tables from which to generate entities and have a syntax to indicate that the entity based on one table should inherit from the entity based on another. Custom code goes in partial classes. So our solution looks most like my option 1 from above.
Also, we started out generating fluent configuration in OnModelCreating in the DbContext but have swapped to using attributes on the Entities (where attributes exist - HasPrecision was one that we had to use fluent configuration for). We found that it is more concise and easier to locate the configuration for a property when it is right there decorating that property.

dynamic creating class in C#

I want to know if there is a way to generate the class dynamically at runtime. I want to use it in Entity framework code first.
Consider if I have 100 tables(or connect to unknown database) I will have to create model/POCO for each table in EF Code First, instead of this I want to generate the POCO class and all its properties at runtime based on the database connected.
Probably not.
Consider this... If the classes aren't defined before compilation, then how is any other code going to use them? If no other code is going to use them, why do you need them?
You can generate objects based on the table schema at design time. Doesn't Entity Framework in fact do this already?
I realize that I've linked to something that is "database first" instead of "code first" but, well, that's what you're asking:
I want to use it in Entity framework code first.
[...]
I will have to create model/POCO for each table in EF
You have a database, and you want to generate models based on the schema of that database. That's database-first.
You can use the EF Power Tools (beta 3) for Visual Studio 2010 or 2012 to reverse engineer a database to POCOs. After installation, right click on a project and select Reverse Engineer Code First under the new Entity Framework menu group.
The Power tools: http://visualstudiogallery.msdn.microsoft.com/72a60b14-1581-4b9b-89f2-846072eff19d
Rowan Miller has a blog post about this, and some advanced uses: http://romiller.com/2012/05/09/customizing-reverse-engineer-code-first-in-the-ef-power-tools/

When I used TPH, all the tables recreated

I am developing an EF - MVC 3 application. I have used model first approach, so I have create model first and from that model, EF generated the DB.
I have used a tool called Nuget - Entity Generator - Database designer for generating the database. When I have designed the model first time, I have used the Generate Migration T-SQL and Deploy option of that tool.
Database generated perfectly and it's working fine...
Now I have come across a situation that I have to make a change to the model and I have to use T-SQL Via T4 (TPH) option to update the database.
So previously I used different process to update DB and now I am changing it.
When I use the T-SQL Via T4 (TPH) all the tables get deleted and new tables get created.
How to avoid this ?
I want to only update the table which I have made the changes.
Entity framework 4.3 comes with migration support. This is not available in EF 4.1.
Some links from google:
http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-automatic-migrations-walkthrough.aspx
http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-code-based-migrations-walkthrough.aspx

Regenerating entity objects via EDMGEN in an MSBUILD project

I have my build executing edmgen successfully however it's generating entity objects for all of my database tables. What I'd like to have it do is only generate for select tables like it currently does in the project locally.
I'm using full generation and passing in a connection string.
There is no possibility to work with a subset of objects in EDMGen. You can try creating a new schema containing only the necessary tables, and run EDMGen for this schema only.
Alternatively, you can create your own version of EdmGen by using the EdmGen2 code base.
In the ModelGen method you can define EntityStoreSchemaFilterEntry filters to select which tables you want.