I need to remove a column from the database in EF 4.3. The database has updated successfully, but the scaffolding is still there for the CRUD views and errors when trying to access them. Is there a way to auto remove scaffolding once the model changes, or do I have to manually delete all instances?
I'm not sure, since I don't know what scaffolding generator you're using. If it's the one that "comes with the box", I'm pretty sure you have to delete the CRUD manually.
The scaffolding generators I'm familiar with are just generators. They don't maintain an awareness of what's been generated, so they don't respond to data model changes. It's a a oneway process.
OTOH, that also means you can probably "eliminate" the scaffolding gunk by rerunning the generator. You'd have to save the customized bits you've added to the scaffolding output, of course, but that may be simpler than deleting what's no longer needed.
Related
I am sorry if I am asking something that has an obvious answer, but I have spent and entire day searching for resources on the subject and I fail to find or understand how to do a few basic thing with EF7.
So, here is my question.
I have an ASP MVC 5 (VNEXT) website and I am using Entity Framework 7. I have an existing database, thus I am working database-first.
So far everything was fine. I installed everything required to get my DNX EF commands up and working; I scaffolded a dbContext and I got all my tables as classes and a dbContext class.
Everything fine, all well. I was happy and continuing with my work.
However, I got to a point where I wanted to make a property of one of the generated (table) classes Required, because I use jQuery unobtrusive validation.
I have the following resource as a reference: http://ef.readthedocs.org/en/latest/modeling/required-optional.html
My first wonder is, according to this source, in the FluentAPI the property has been marked as .IsRequired(). I believe, making it required here is a whole other thing that has nothing to do with unobtrusive validation. So, the next thing explained is simply - go to your class and add the Required data annotation.
This is all fine and well, and after adding it, it works as it should.
But I immediately wondered - well, I am modifying the generated classes, am I not going to lose those changes once I update the model?
Which leads me to my final problem - I searched for a long time, I even played with the help menu of DNX EF, but I am unable to find the right way to update the dbContext and generated models after I make changes to the database.
I believed this to be something quite trivial but to my surprise I am unable to find a resource explaining how to do the update.
Can you point me in the right direction, and tell me how to update EF generated models and context after I make changes in the database schema, and what is the best way to add annotations to the properties of the generated classes?
The general consensus is that you shouldn't use your database entities as input from users directly. Instead, use ViewModels, verify those against your validation rules, then map them to database transactions.
As asp.net MVC developer I use database first and updating database is a big head ache so I use Metadata approach and create ViewModels which helps allot.
I am changing the model of my Core Data app in a big way for the next update, and custom migration is definitely needed. After reading Apple's docs on migration policy, I find it very confusing and wondered if there is an easier way. I am thinking, why not just bring up the data in the old context/model, and bring up a blank context with the new model, and copy object one by one into the new context/model and perform any needed logic in between? This way, I can even make use of logic in my NSManagedObject subclasses to construct data in the new model instead of working with the mechanism in migration policy. Has anyone tried something like this with any success?
I have several database tables that the user should be able to add, edit and remove entries from the web application.
Also the input must be validated before persisting it.
Now I could simply make a table and put labeled input fields in there, but the result would be far from DRY and a horror to maintain. Composite components make this just a bit better. Is there any alternative I do not see which could reduce a lot of work?
If I'm not misunderstanding the question, one concept you might wanna look into is generic/generated CRUD.
Netbeans has a primefaces CRUD generator link
I've used mvcScaffolding and mvc3 to generate my tables in a sql2008 database. some data has been added.
I've changed a single model and wish to alter the underlying table.
is there a way to auto-update a single table to keep it in sync with the model?
after adding a new model how can the database table be created without recreating the database
You're looking for something like Rails' migrations. There are a couple .NET migrations providers floating around, but the basic setup you've described doesn't support alterations to the schema without recreating the database (at least in my experience).
have you tried treating your database an an existing one as described in this example by Scott Gu?
http://weblogs.asp.net/scottgu/archive/2010/08/03/using-ef-code-first-with-an-existing-database.aspx
Hopefully thias way you will not have to re-create your db everytime a change is required...
Regards
Paul
I'm just starting a project in ASP.Net MVC with LINQ to Entities and I was wondering if there was a nice, clean way of defining models that creates the appropriate tables in the database for me. I'm most familiar with Django (in terms of MVC frameworks) and am looking for the .Net equivalent of models.py so I can have everything versioned. Any ideas? It would be even better if it had some form of schema migration, a la django-evolution and the like.
I think what you want to do is to turn the question around. Entities can be automatically generated from the database, so the issue is simply using a .NET mechanism to maintain your database schema. Since you're not using NHibernate, which these other solutions require, I would suggest using MigratorDotNet. MigratorDotNet uses exactly the same idea as Ruby on Rails migrations:
Your database keeps track of its version
Every time you wish to change the schema, you write a small class to handle the upgrade (and, optionally, downgrade)
Assign these classes an execution order
If the database is ever not up-to-date, simply execute the classes' upgrade methods in order
Since you'll only be regenerating your Entities at compile time, I'd recommend running the migration scripts, and then regenerating your entities, as a part of your build process. MigratorDotNet already comes with an MSBuildTarget, adding it will just involve a couple of clicks.
Another option is to use NHibernate with FluentNhibernate which will auto map your model based on conventions. You can also override a mapping to tweak it for your needs.
Castle Project active record is a nice way of doing it.
If offers capabilities similar to ruby on rails active record.