I use SQL Server 2008 and Entity framework 4.1 database first approach .
Is there any way I could create null-able Computed column ?
I can't create like this :
Alter Table Employee Add FullName nullable as LastName + ' ' +FirstName
If the answer is NO , then Is there any way I could make the appropriate Scalar Property Nullable
in EDMX File of EF Which map to Computed column ?
Computed columns by default nullable is the expression involves any other nullable column, expression or any function. If you want NON-NULL computed column, you should wrap the column's expression with ISNULL function.
Alter Table Employee Add FullName as LastName + ' ' +FirstName
In this case FullName will be nullable only if one of columns (FirstName, LastName) will be nullable too
If you want nullable computed column composed witn non-nullable expression columns, then use the User Defined function as expression:
CREATE FUNCTION dbo.FullName(@LastName nvarchar(100), @FirstName nvarchar(100))
RETURNS nvarchar(201)
AS
BEGIN
RETURN @LastName + N' ' +@FirstName
END
GO
Alter Table Employee Add FullName as dbo.FullName(LastName, FirstName)