LinqToSql Nullable<>

Posts   
 
    
Posts: 134
Joined: 10-Jan-2007
# Posted on: 29-Jun-2010 21:00:00   

When generating LinqToSql classes, all fields are being generated as Nullable<>.

I think I have narrowed it down to the generalTemplateUtils.lpt line 80:

return GeneratorUtils.ProduceDotNetTypeName(toPass, true, nullablePattern);

Looks like passing true to GeneratorUtils always outputs Nullable<> for value types. Should the call be passing the IsOptional of the field instead of true?

Brian

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 29-Jun-2010 21:48:54   

IsOptional is a flag of 'toPass'. We'll look into it. (we didn't see Nullable<T> fields everywhere in our tests...)

Frans Bouma | Lead developer LLBLGen Pro
Posts: 134
Joined: 10-Jan-2007
# Posted on: 29-Jun-2010 21:57:21   

'toPass' is a Type. There are 2 overloads for ProduceDotNetTypeName:

internal static string ProduceDotNetTypeName(IFieldElementCore field, Project currentProject, string nullablePattern)

and

internal static string ProduceDotNetTypeName(Type dotNetType, Project currentProject, string nullablePattern)

The first is used pretty much all over and just calls the second passing the field.FieldType.RepresentedType. No IsOptional is passed, the second looks to handle the "PreferBinaryTypeOverByteArray" setting.

Brian

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 29-Jun-2010 22:11:36   

(I didn't look at the templates when I wrote the previous post, it's been 4 months or more ago when I wrote them flushed )

Hmm. I now see you're right, our tests indeed emit Nullable<T> everywhere for L2S. Weird. Will fix it tomorrow (wednesday)

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 29-Jun-2010 22:28:12   

Looks like this is caused by a change in the API we made late in the process when NHibernate templates were almost done which made this change pop up. So indeed an issue we have to correct.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 30-Jun-2010 12:25:27   

Fixed in next build. I also found an issue with compound FK fields which were nullable, as the anonymous types wouldn't always match in joins.

Frans Bouma | Lead developer LLBLGen Pro