tags:

views:

29

answers:

1

I have a case where I have a linq2sql dbml with 2 table in it

let simplify this by:

Table1
id int not null
fkid int not null (to table2.id)

and

Table2
id int not null
v1 bit not null

in the generated dbml, fkid is not the type nullable and by default it's value is 0

but in table2, I don't have an id 0

when i'm trying to insert a new record without touching fkid field, I'm getting an SQL insert error saying: 0 doesn't exist into table2

thing is I want to make to make my check fully generic so I cannot just do something like:

if column doesn't allow null check if value is 0 and if it's the case throw a custom error

I would like to do something like: if column is null then throw "my custom error"

how would you implement that?

A: 

since I'm using t4 template, I changed the line 80 in L2ST4.ttinclude from

if (type.IsValueType && canBeNull)

to

if (type.IsValueType)

so it ALWAYS set nullable type everywhere in the generated file

Fredou
I just moved this from my question so I can give it a green check in 2 days, if there is no better answer
Fredou