|
Can you elaborate on that please?
|
|
|
|
|
Here is an example click[^]
It can generate scripts and apply them to the database based on changes made to the POCO classes used.
|
|
|
|
|
I built a large project with code first using MS MVC (a couple of years ago) and felt that I addressed one of the major problems in programming. One of my basic rules of project development has been YOU BETTER GET YOUR DATABASE DESIGNED FIRST OR YOU WILL REALLY DESTABILIZE THE APP WHEN YOU MAKE CHANGES TO THE DB MIDSTREAM. Sometimes, however, you just don't have that luxury and Code First really helps in that scenario. With code first you focus on your classes and so you can work and think at a truly theoretical level. Changes to classes and new classes migrate to the DB at the push of a button and so there is never any lag between design and implementation when making design changes.
That is the high level view. You are free to work and think at a class level. The companion to code first is LINQ. With code first and LINQ you can literally design and built a complex system and never even look at the database. It is a very cool experience.
There are some considerations. The key one is test data. When you 'recycle' your DB after class / design changes you often need to migrate test data. When I was working on my code first project, MS had some data migration hooks but I just ended up building a routine to re-populate the test data. I am sure it is better now.
I felt Code First was a useful technique when building a system from the ground up.
|
|
|
|
|
Neither. I prefer to hand create both. Call me old school, but I don't trust auto created databases or entity layers. Too many times someone makes a "minor" tweak to one or the other and then forgets to regenerate, then you're hosed.
|
|
|
|
|
Vark111 wrote: I don't trust auto created databases or entity layers.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Vark111 wrote: Too many times someone makes a "minor" tweak to one or the other and then forgets to regenerate, then you're hosed.
I have read, and heard, many stories about this. It is one of our concerns.
|
|
|
|
|
But how many times has someone updated one, and forgot to update the other? At least with auto-generation, you're one click away from regenerating. With code first, you need to sit down and verify every recent change to ensure it has been incorporated.
|
|
|
|
|
I am not sure how this can happen.
If you were using Entity framework, i know this can't happen. EF will inform you that the database and the POCO are out of sync.
Also, EF7 is strictly going to be Code first, though you have the option of generating the classes form an already existing db, but after that code first.
I think i prefer code first a lot, its very RAD, and migrations allow me to tweak almost anything nowadays.
|
|
|
|
|
Layinka wrote: EF7 is strictly going to be Code first
Good to know.
|
|
|
|
|
I agree
modified 19-Jan-21 21:04pm.
|
|
|
|
|
Thank you. I have not tried it yet and its nice to hear not everyone is jumping on the bandwagon. Using a wizard to create your database just sounds like trouble.
|
|
|
|
|
I like to roll my own too - if you know what you are doing then it works well.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
GuyThiebaut wrote: if you know what you are doing
Exactly; from what I see, the "latest and greatest shiniest new" tools are designed for a different demographic.
If you don't know what you're doing, better have someone else do it for you.
|
|
|
|
|
Old school here too. I can't recall the last time I let either DB or code be auto-created for me.
|
|
|
|
|
Not really, no.
It feels better to start with but when you have a decent size model you basically have no way to visualise it except turning it into a database and then looking at that.
|
|
|
|
|
I have seen the many-tentacled monsters manifested from the murky depths of Code First. Epi's with their SAS armor fear to step within the shadow of these Lovecraftian beasts. The Oracles on high, throw ever more power against it, and the leviathan will not be sated. When it takes 109 left joins, 20 sub-selects and 17 decodes to pull a single death record, there is nothing but eye-clawing madness and sound of your own screaming.
So... no. I do not like Code First.
|
|
|
|
|
I wouldn't know how to normalize a code-first model
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Just saw a demo online a few days ago, and the "demo guys" were having trouble with some areas with code first, and they were the "experts". So far, I am not entirely convinced that it is a development strategy worth using for the long term. We shall see, I guess.
|
|
|
|
|
Slacker007 wrote: Just saw a demo online a few days ago Still got the link?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Tx
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
Slacker007 wrote: Just saw a demo online a few days ago, and the "demo guys" were having trouble with some areas with code first, and they were the "experts". Can you share the link?
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
My buddy has it. Will post back with it when I get it. I watched part of the vid clip on his machine, not mine.
|
|
|
|
|
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Learn ASP.NET Online – Microsoft Virtual Academy[^]
Under "Creating and configuring models" --> Creating models --> around 23:40 but start at around 22:00 to get some intro context.
I heard that the SNAFU they had during the demo happens a lot to people, especially those who are trying to get up to speed with "code first".
|
|
|
|