Nullable types in views vs. tables

Posts   
 
    
magic
User
Posts: 125
Joined: 24-Nov-2008
# Posted on: 17-Nov-2009 20:38:57   

I just ran into trouble because I was using the .IsNullable property on a field that is coming from a view, but it is imported into the project as an entity (based on a typed view).

I did some reading about this topic here: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=16282

The problem is though that if I develop logic that is based on an EntityField2 (and no knowledge - at least for now) from "where this field comes" (a table or a view) since the entity can be based on both, how do I know whether I can trust the .IsNullable property?

Is v3.0 supposed to handle this stuff differently?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 17-Nov-2009 21:53:46   

the problem is sqlserver, (and other db's as well, though sqlserver mainly) which doesn't update meta-data of a view when the tables in the view change.

In v3 we indeed obtain the meta-data as-is from the db and with nullability. Does that help? no. the thing is that if a field in a table is changed to be nullable, the view(s) the field is in won't be updated, at least not in the sqlserver meta-data.

Frans Bouma | Lead developer LLBLGen Pro
magic
User
Posts: 125
Joined: 24-Nov-2008
# Posted on: 17-Nov-2009 22:24:35   

I know that SQLServer is trouble! wink Nevertheless some people are not asked and have to work with it. rage

What I'm trying to understand is how (or whether) I can use the .IsNullable property at all.

Since I don't know whether it is "coming from" a view or a table, how do I know whether I can trust it or not? Remember that I use LGP entities based on typed views too.

Also, why does LGP set the .IsNullable property to false for all columns of an entity based on a view? Why not "just" say it is unknown = null?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 18-Nov-2009 06:02:55   

magic wrote:

I know that SQLServer is trouble! wink Nevertheless some people are not asked and have to work with it. rage

That's the way it is unfortunately

magic wrote:

What I'm trying to understand is how (or whether) I can use the .IsNullable property at all.

Since I don't know whether it is "coming from" a view or a table, how do I know whether I can trust it or not? Remember that I use LGP entities based on typed views too.

So, in short, you want to know whether an "entity" is based on a "table" or on a "view" to know if you can trust in IsNullable property. Well, AFAIK you can't. However you could add a custom property to each "entity based on a view" to flag it, then you could access that property (using the CustomPropertiesOfType entity's property) and know if you can trust on it.

magic wrote:

Also, why does LGP set the .IsNullable property to false for all columns of an entity based on a view? Why not "just" say it is unknown = null?

SqlServer doesn't update the nullability state of a view field when the nullability of a table field changes (which is in a view). This thus leads to errors, hence that piece of retrieval code is commented out the code in the driver. More info: http://llblgen.com/tinyforum/Messages.aspx?ThreadID=14825

David Elizondo | LLBLGen Support Team
magic
User
Posts: 125
Joined: 24-Nov-2008
# Posted on: 30-Dec-2009 05:26:41   

First of all (as I already stated a couple of times), I understand that MsSQL sucks and there's not much one can do about it. wink

But ... why is LGP converting nullable types into not nullable? I have a view that has a nullable boolean field. The value of this field in a particular row is NULL, but when I try to access the value through the LGP entity, it is FALSE. This totally falsifies my data! frowning LGP does the same for numeric values (turns them to 0), but not with strings where the value stays NULL.

If no assumptions can be made about whether a field is nullable or not, it should be nullable and not assigned a value that isn't there?

Furthermore, I have tried to read through the thread that you suggested, and I don't think I can follow. confused Can you please elaborate more on the idea of changing the source code in SqlServerSchemaRetriever.cs, line 1263? How am I supposed to do that?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 30-Dec-2009 09:32:14   

This will be handled in v.3.0

Can you please elaborate more on the idea of changing the source code in SqlServerSchemaRetriever.cs, line 1263? How am I supposed to do that?

You should get the Drivers source code, found in the SDK package. (Download it from the website).

magic
User
Posts: 125
Joined: 24-Nov-2008
# Posted on: 30-Dec-2009 13:11:41   

I think I'm really too stupid to find the download. Sorry.

Can you please provide a link or instructions? Thank you.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 30-Dec-2009 13:39:02   

magic wrote:

I think I'm really too stupid to find the download. Sorry.

Can you please provide a link or instructions? Thank you.

customer area -> v2.6 (left side) -> Extras -> LLBLGen Pro SDK simple_smile

Frans Bouma | Lead developer LLBLGen Pro