Viewing entries tagged
entity framework


Entity Framework madness… all over again

Entity Framework is a great tool for quick and dirty data mappings and management. I encourage it for POCs and throw away pet projects, but will never even consider it for a production application. There are thousands of reasons for this; mainly they revolve around the scalability problems, performance issues with caching and lazy loading data and just plain fucked-up things that EF forces you to do in some cases, like break good design patterns. Here is a new one for me: EF does not support gracefully Non-Nullable columns with default values in the form of expressions. Let me break that down for you. Say you create a table in your schema with a column like this;

[sourcecode language="sql"][CreationDate] [datetime] NOT NULL DEFAULT (GetDate())[/sourcecode]

If you generate your edmx with Entity Framework and start adding records to your table, you’ll note at first your values look like this:


… and then you are like WTF! Yes, WTF is that Entity Framework does not support such thing as of the writing of this article (02/29/2012). Here is a post from Microsoft Connect explaining the problem:

So what do you do?

Option 1: Don’t use Entity Framework

Option 2: Manually change the edmx XML by hand and every time you modify your schema you have to do it again. This option is kinda stupid, because I ONLY recommend the use of EF in for prototyping projects, which in turn change a lot, thus annulling the initial reason to use EF in this setup: SPEED. But let’s go with it.

In case you want to support such case, you need to open your edmx file in your favorite text editor as XML and search everywhere your field is referenced in the file like so:

[sourcecode language="xml"][/sourcecode]

And like

[sourcecode language="xml"]<ScalarProperty Name="CreateDate" ColumnName="CreateDate" />[/sourcecode]

And remove them. Just beware that next time around if you need to update your Entity Data Model because you changed your schema, you’ll have to go through this all over again.

I tried this Stack Overflow solution but didn't have much luck:



New product coming...

I'm starting a new project/product now. Let's see how it goes, I have very high expectations with this new product and I'll let things slip thru as it takes shape. I still have to make a new company for it, so I can get some tax benefits too. I keep postponing the company creation thing for tomorrow and then for tomorrow. One more time, I'll do it tomorrow (and this time I'll really do it). I'll kick things up with .NET 4.0 and some Entity Framework. This is my first time working with the ADO.NET entity framework and I like very much what I've seen so far. Initially I thought to use something different from .NET, like RoR (Ruby) or Django, the Python Web framework; but I ended up going back to the land I know the best: .NET world. The reason was simply the speed at which I can work and produce code is important at this time, since I'm the only one writing code on this thing.

I'll try to keep posting about my progress here and the new challenges I face as I move forward.