.NET Nullable types

Posts   
 
    
Syc0F3ar
User
Posts: 14
Joined: 20-Sep-2005
# Posted on: 20-Sep-2005 22:51:32   

Is there support built in for the .NET 2.0 nullable types? Or is this something I would need to create a type converter for?

Paul.Lewis
User
Posts: 147
Joined: 22-Aug-2005
# Posted on: 21-Sep-2005 04:09:03   

Syc0F3ar wrote:

Is there support built in for the .NET 2.0 nullable types? Or is this something I would need to create a type converter for?

LLBLGen Pro v2.0 for .NET 2.0 supports nullable types.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 21-Sep-2005 08:28:25   

Exactly, this beta doesn't support nullable types. You COULD create them with a type converter though. Your typeconverter has to convert normal value types as well, as a PK obviously doesn't have a nullable type.

Frans Bouma | Lead developer LLBLGen Pro
tvuong
User
Posts: 17
Joined: 27-May-2005
# Posted on: 27-Sep-2005 22:01:03   

Do you have a sample that I can look @. I feel a bit slow.

pilotboba
User
Posts: 434
Joined: 05-Aug-2005
# Posted on: 28-Sep-2005 16:20:04   

Otis wrote:

Exactly, this beta doesn't support nullable types. You COULD create them with a type converter though. Your typeconverter has to convert normal value types as well, as a PK obviously doesn't have a nullable type.

How?

Do you have the ability to change the .Net type that is generated?

I don't see any way that I could chanage a property to be generated as DateTime? rather than DateTime.

Wouldn't I need to be able to specify a nullable type for a field in order to create a type converter?

BOb

tvuong
User
Posts: 17
Joined: 27-May-2005
# Posted on: 29-Sep-2005 18:27:03   

I created two TypeConverters and added them to the folder. The 2003 shows up on the drop down, but the 2005. Otis, do you know why?

Thanks,

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 30-Sep-2005 06:39:37   

pilotboba wrote:

Otis wrote:

Exactly, this beta doesn't support nullable types. You COULD create them with a type converter though. Your typeconverter has to convert normal value types as well, as a PK obviously doesn't have a nullable type.

How?

Do you have the ability to change the .Net type that is generated?

I don't see any way that I could chanage a property to be generated as DateTime? rather than DateTime.

You probably can't because it's a .NET 2.0 type and the application is .NET 1.x. You could however use the nullable types for .NET 1.x, it's a 3rd party lib available on sourceforge (lgpl-ed). So you can then write a type converter, which has as core type NullableDateTime, and converts from datetime to NullableDateTime and back. The designer will allow you to set that typeconverter on a field of type DateTime, and the .Net type of the field will change to NullableDateTime. Exactly as what the example typeconverter does with int/byte etc. fields converted to bool fields.

Wouldn't I need to be able to specify a nullable type for a field in order to create a type converter?

No, by applying the type converter, you specify that the field has the .NET type of the typeconverter. The conversion from/to the actual .NET type belonging to the db type of the field is done by the type converter object and is done transparently behind the scenes for you, so you don't see that conversion, the property is NullableDateTime, the value in the EntityField object is NullableDateTime etc.

Frans Bouma | Lead developer LLBLGen Pro
pilotboba
User
Posts: 434
Joined: 05-Aug-2005
# Posted on: 03-Oct-2005 19:06:18   

Otis wrote:

No, by applying the type converter, you specify that the field has the .NET type of the typeconverter. The conversion from/to the actual .NET type belonging to the db type of the field is done by the type converter object and is done transparently behind the scenes for you, so you don't see that conversion, the property is NullableDateTime, the value in the EntityField object is NullableDateTime etc.

Ah, I wasn't aware that is how it worked. I assumed I would have to change the type.

I assume the designer uses reflection to determine the return type of the type converter then changes the property type accordingly. Is that what you are saying?

Bob

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 04-Oct-2005 13:58:57   

pilotboba wrote:

Otis wrote:

No, by applying the type converter, you specify that the field has the .NET type of the typeconverter. The conversion from/to the actual .NET type belonging to the db type of the field is done by the type converter object and is done transparently behind the scenes for you, so you don't see that conversion, the property is NullableDateTime, the value in the EntityField object is NullableDateTime etc.

Ah, I wasn't aware that is how it worked. I assumed I would have to change the type.

No, that's done for you simple_smile

The type converters have one target type and support for 1 or more sourcetypes. For example, the shipped type converter has as target type System.Boolean and as sourcetype int, byte, sbyte, uint, ushort, short, long and ulong.

I assume the designer uses reflection to determine the return type of the type converter then changes the property type accordingly. Is that what you are saying?

Type converters are derived classes from System.ComponentModel.TypeConverter. This class has nice methods like 'CanConvertFrom' and 'CanConvertTo'. So, when a field selection changes, the editor calls all type converters to see if they can convert from the type of the current field. If so, the type converter is added to the list to select from. simple_smile .

So a typeconverter developer just has to implement these methods and it works automatically.

Frans Bouma | Lead developer LLBLGen Pro