A friend reported a problem with a computed column, Entity Framework, and Breeze
We have a table with a "FullName" column computed by the database. When creating a new
Person
, Breeze sends theFullName
property value to the server, even though it’s not being set at all, and that triggers an error when trying to insert the newPerson
instance. The database throws this exception:
The column "FullName" cannot be modified because it is either a computed column or is the result of a UNION operator.
Here is the relevant portion of the SQL Table definition:
CREATE TABLE [dbo].[Person]( [ID] [bigint] IDENTITY(1,1) NOT NULL, [FirstName] [varchar](100) NULL, [MiddleName] [varchar](100) NULL, [LastName] [varchar](100) NOT NULL, [FullName] AS ((([Patient].[LastName]+',') + isnull(' '+[Patient].[FirstName],'')) + isnull(' '+[Patient].[MiddleName],'')), ...
My friend tells me the corresponding "Code First" class looks something like this:
public class Person { public int ID {get; set;} public string FirstName {get; set;} public string MiddleName {get; set;} public string LastName {get; set;} public string FullName {get; set;} ... }
The answer to this question explains the problem and offers a solution.