Model first with EDM?

In my previous post, I managed to update a simple model from an existing database. But then I started trying to do things like build my project and ran into so many problem trying to get my simple model to interact with the AdventureWorks database that I finally gave up.

I actually wrote my thoughts on this in a question on the MSDN forum for Entity Framework, with the point of the question being "is there a real example of this? Or is it just a concept that looks good on paper?"

I care a lot about this becuase I have been sharing this concept (which does make sense to me) that the EDMs loose coupling to the database means that you could map the CSDL to different databases.

But the AdventureWorks database just had too many constraints – such as non-nullable fields that I didn’t have in my model and I finally gave up because it was forcing me to modify the CSDL and I would also have to add in some business logic to deal with some of these non-nullable fields. And even if I did that, who knows what other problems would pop up?

Update after I gave myself a little time while eating lunch to think about this some more, I crossed out "finally gave up" becasue it’s basically not in my nature. I decided to go about this in a different direction with just ONE entity and succeeded by removing the unused non-nullable fields from the SSDL and mapped the entity to Insert/Update/Delete sprocs. All I have to say to myself at this point is "well, duh!" The insert stored proc provides the missing non-nullable fields and the update stored proc updates the modifieddate for me. SO problem solved in a not very realistic example, but I plan to build it up thought not today – I’ve already invested too much time. There’s a lot of flexilibity in the model, but we all still have a lot of learning to do for our various use cases.

You can read my more complete thoughts on this in the forum post and if you want to follow the conversation you can sign up to get alerts on this thread from the MSDN forums.

Oh, and if you’ve never signed up for alerts before, you might want to read this blog post I wrote last summer: A few MSDN Forums tips (which I learned the hard way – as usual).

  Sign up for my newsletter so you don't miss my conference & Pluralsight course announcements!  

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.