Here is my example view (contrived I know but shows my problem):
CREATE VIEW NullTest
AS
SELECT
1 AS IntNoConvert,
CONVERT(BIT, 1) AS IntConvert,
CAST(1 AS BIT) AS IntCast
The final views as the data types as:
IntNoConvert (int, not null)
IntConvert (bit, null)
IntCast (bit null)
So the CONVERT and CAST make the column allow NULLs – not normally a problem in views but am I am using LinqToSql ontop of this, I need the datatypes to be NOT NULL.
Any ideas how to make the CONVERT statement return the data as NOT NULL?
Use the SQL IsNull function to ensure non-nullability:
This feels a little hacky so I agree with a1ex07’s comment that you should define the non-nullability in your model instead.