edmx to Code First migration process

Feb 25, 2014 at 12:17 PM
Hi there.

We are busy converting to code first models from edmx.
We have 2 tables:

Clouds and CloudStates. The latter is a lookup table.
Cloud has a StateId column that is a FK to CloudStates.Id

Now, with the edmx, we deleted the CloudeState.Clouds navigation property that was generated for us when updating from the DB because you should never navigate from a CloudState instance to all the clouds in that state. (because of EF's gready materialisation of collection properties, and NOF sometimes recursively walks down to these to display counts on the generated UI, and the combination causes performance hits.)

We must now achieve the code first equivalent. As you have had experience, you could perhaps give us a tip?

Using the EF powertools generator, we have generated the following from the DB.
this.HasRequired(t => t.CloudState)
    .WithMany(t => t.Clouds)
    .HasForeignKey(d => d.StateId);
Now, since we want to delete the CloudState.Clouds collection property, the following line will obviously not compile.
    .WithMany(t => t.Clouds)
Can we simply delete it, like so?
this.HasRequired(t => t.CloudState)
    .HasForeignKey(d => d.StateId);
Anything we should watch out for?

Thank you much.

PS This is just an example, we do mostly map our lookup tables to .Net enums.
Feb 25, 2014 at 1:28 PM

This is really a standard EF question, not anything to do with Naked Objects per se. I recommend posting on Stack Overflow. (Though if you experimented a bit, I think you'd find that it is all quite straightforward).

Feb 25, 2014 at 3:30 PM
Will do, Richard.