Click here to Skip to main content
12,999,081 members (48,323 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi experts

I got a table in SQL Server 2008 has 10 columns and one of them is a computet column
(([FirstName]+n' ')+[LastName])

But when I try to insert a new object to the table with entityframework 4, it can't and an exception like computed column can not be null

But if I remove the column form the table it can be inserted.

I use .NETFramework 4 and Visual Stadio 2010

What can I do to solve this problem it's necessary to have computed column and EF4 doesn't work for this.
I don't want to use SP (Stored Procedure) too?
Posted 5-May-12 1:47am
Updated 5-May-12 11:24am
Wes Aday 5-May-12 8:07am
If you have a constraint on the computed column that is cannot be null, remove the constraint.
Vartan Khachatourian 5-May-12 8:45am
it's not null because firstname and lastname are not null
Wes Aday 5-May-12 8:47am
What exactly does that have to do with a constraint on the database column?
Vartan Khachatourian 5-May-12 8:51am
there is not any constraint on this column
Wes Aday 5-May-12 8:52am
Well that is where you are getting that error.
Vartan Khachatourian 5-May-12 8:53am
well whats your solution?
Zoltán Zörgő 5-May-12 17:04pm
Are you using
Vartan Khachatourian 5-May-12 17:25pm
no but if i must use it , where am i supposed to add the arrtibute?
Zoltán Zörgő 5-May-12 17:49pm
Well this is a DataAnnotation attribute. You should put it where your other attibutes are. Are you following database-first or code-firts approach? I suppose the first one. In this case it is a little bit difficult to add attributes: you can use partial classes. Here you have an example:
Zoltán Zörgő 6-May-12 0:34am
Another: you can use a read-only not mapped property in EF instead of calculate in on sql side. You will probalby gain performance too.
Vartan Khachatourian 6-May-12 6:01am
thank you i try it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170622.1 | Last Updated 5 May 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100