Type converters for .NET 2.0 nullable types

Posts   
 
    
Deivis
User
Posts: 23
Joined: 22-Aug-2005
# Posted on: 27-Sep-2005 12:09:27   

Hello,

has anyone created type converters for .NET 2.0 nullable types? I could create them myself, but I'm lazy simple_smile

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 03-Oct-2005 12:51:38   

Deivis wrote:

Hello,

has anyone created type converters for .NET 2.0 nullable types? I could create them myself, but I'm lazy simple_smile

You're not alone in that as it seems wink stuck_out_tongue_winking_eye

I'll try to squeeze an example into the final release if there's time, though with NullableTypes for .NET 1.x. The main issue is that the type converters have to express the type they're converting to and that can't be a .NET 2.0 type as the designer is a .NET 1.1 program.

Frans Bouma | Lead developer LLBLGen Pro
Deivis
User
Posts: 23
Joined: 22-Aug-2005
# Posted on: 03-Oct-2005 15:22:52   

Otis wrote:

The main issue is that the type converters have to express the type they're converting to and that can't be a .NET 2.0 type as the designer is a .NET 1.1 program.

What about a LLBLGenPro version compiled with .NET 2.0? That way we could use .NET 2.0 nullable types and there wouldn't be much hassle maintaining two versions of the program (only recompiling). simple_smile

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 03-Oct-2005 17:06:17   

Deivis wrote:

Otis wrote:

The main issue is that the type converters have to express the type they're converting to and that can't be a .NET 2.0 type as the designer is a .NET 1.1 program.

What about a LLBLGenPro version compiled with .NET 2.0? That way we could use .NET 2.0 nullable types and there wouldn't be much hassle maintaining two versions of the program (only recompiling). simple_smile

If it would have been that simple, I would have done it immediately.

The sad part is... there's somehow a mismatch between the encryption of signed xml files in .net 1.x and 2.0, or in other words: using the old license files on .NET 2.0 somehow don't work. (for example, modify the .config file of llblgen pro to force it to use .NET 2.0 -> license error. )

Frans Bouma | Lead developer LLBLGen Pro
pilotboba
User
Posts: 434
Joined: 05-Aug-2005
# Posted on: 03-Oct-2005 22:17:51   

Otis wrote:

Deivis wrote:

Otis wrote:

The main issue is that the type converters have to express the type they're converting to and that can't be a .NET 2.0 type as the designer is a .NET 1.1 program.

What about a LLBLGenPro version compiled with .NET 2.0? That way we could use .NET 2.0 nullable types and there wouldn't be much hassle maintaining two versions of the program (only recompiling). simple_smile

If it would have been that simple, I would have done it immediately.

The sad part is... there's somehow a mismatch between the encryption of signed xml files in .net 1.x and 2.0, or in other words: using the old license files on .NET 2.0 somehow don't work. (for example, modify the .config file of llblgen pro to force it to use .NET 2.0 -> license error. )

I wonder if this is a simmilar issue to sharing cookies with 1.1 and 2.0:

Forms authentication cookies can be used between 1.1 and 2.0.

o 2.0 uses AES encryption by default

o To have this work change the machine Key in web.config. To do this explicitly set the validation key and machine key for 1.1. For 2.0 change the decryption attribute to "3DES".

o 2.0:

Can you specify 3DES in the code so both 2.0 and 1.1 will use that?

BOb

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 03-Oct-2005 23:29:37   

thanks for the info! simple_smile I'll check it out tomorrow simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 05-Oct-2005 18:25:40   

Not sure if this is the case... I Use RSA and simply call CheckSignature() on SignedXml. I'll check if that method has changed since .NET 2.0. As I pass in an RSA cryptoservice provider, I don't think a default machine key would have any say in this (but you never know of course wink ).

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 05-Oct-2005 19:10:26   

I found it, apparently on .NET 2.0, you can't use CheckSignature() with a KeyInfo been passed into the object first, it only works when you pass in the key object to the CheckSignature method. It seems to work without a problem (and still does hte same checking wink ). It now can run natively on .NET 2.0. Doesn't seem to be faster though... (at least not debug builds).

Frans Bouma | Lead developer LLBLGen Pro
Syc0F3ar
User
Posts: 14
Joined: 20-Sep-2005
# Posted on: 05-Oct-2005 19:34:35   

Does this mean it will be available in the next build for this version? If so, am I to understand that we could now write a type converter for .NET 2.0 nullable types?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 05-Oct-2005 20:49:00   

Syc0F3ar wrote:

Does this mean it will be available in the next build for this version? If so, am I to understand that we could now write a type converter for .NET 2.0 nullable types?

Yes, that should be possible. simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 06-Oct-2005 11:15:47   

~~I just noticed something. I forgot something to implement which is important: when a PK is synced with the FK, the FK field gets the PK value. Of course, the PK isn't a nullable type. But the FK might be. So instead of getting a value of type X, the FK gets the value of type Y, the same as the PK field. Reading the property of the FK field might create a cast exception, as the property expects a value of type X, not Y.

I have to push the value of the PK through the converter as well, if available, to get a value of type X. ~~ Can't be done, type converter is part of the persistence info, not part of the entity field core. So in adapter, the typeconverter isn't known on the field (rightfully so, as it can have multiple converters, one per db specific project). So a PK type has to be castable to the FK type at runtime. If not, too bad. This isn't a problem per se, just for VB.NET 1.x users, which can't utilize implicit conversion functions on a type.... disappointed


This also causes a problem with the custom relation creation dialog. A custom relation has to be able to be creatable between a PK field of type Int, and an FK field of type Nullable<Int> or whatever type based on Int.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 06-Oct-2005 13:19:49   

Ok, I now have a type converter with Luka's NullableTypes. (for .NET 1.1). They're not optimal (e.g.: databinding sux) but can be used in general quite easily:


[Test]
public void InsertDeleteBoardMemberNullableTypeTest()
{
    using(DataAccessAdapter adapter = new DataAccessAdapter())
    {
        adapter.CatalogNameUsageSetting = CatalogNameUsage.Clear;
        BoardMemberEntity newBoardMember = new BoardMemberEntity();
        // Employee's fields
        newBoardMember.Name = "Frans Bouma";
        newBoardMember.StartDate = DateTime.Now;
        // rest is null.

        Assert.IsTrue(adapter.SaveEntity(newBoardMember, true));
        Assert.AreEqual(NullableInt32.Null, newBoardMember.ManagesDepartmentId);
        Assert.IsTrue(adapter.DeleteEntity(newBoardMember));

        newBoardMember = new BoardMemberEntity();
        // Employee's fields
        newBoardMember.Name = "Frans Bouma";
        newBoardMember.StartDate = DateTime.Now;
        newBoardMember.ManagesDepartmentId = NullableInt32.Null;    // set to NULL

        Assert.IsTrue(adapter.SaveEntity(newBoardMember, true));
        Assert.IsTrue(newBoardMember.TestOriginalFieldValueForNull(BoardMemberFieldIndex.ManagesDepartmentId));
        PredicateExpression additionalFilter = new PredicateExpression();
        additionalFilter.Add(PredicateFactory.CompareValue(BoardMemberFieldIndex.Name, ComparisonOperator.Equal, "Frans Bouma"));
        Assert.IsTrue(adapter.DeleteEntity(newBoardMember, additionalFilter));
    }
}

With .NET 2.0, this might be even smoother, but haven't tried it yet. I'll include the sourcecode of the type converter in today's build of the beta.

Frans Bouma | Lead developer LLBLGen Pro
Alfredo avatar
Alfredo
User
Posts: 46
Joined: 12-Dec-2004
# Posted on: 12-Feb-2006 02:26:24   

Hi Frans:

Could you send me or post the type converter for NullableTypes. I desperately need to implement an entry form that accepts null values in decimal columns.

Never mind....I found it in the SDK sample

Thank you

Alfredo

Otis wrote:

Ok, I now have a type converter with Luka's NullableTypes. (for .NET 1.1). They're not optimal (e.g.: databinding sux) but can be used in general quite easily:


[Test]
public void InsertDeleteBoardMemberNullableTypeTest()
{
    using(DataAccessAdapter adapter = new DataAccessAdapter())
    {
        adapter.CatalogNameUsageSetting = CatalogNameUsage.Clear;
        BoardMemberEntity newBoardMember = new BoardMemberEntity();
        // Employee's fields
        newBoardMember.Name = "Frans Bouma";
        newBoardMember.StartDate = DateTime.Now;
        // rest is null.

        Assert.IsTrue(adapter.SaveEntity(newBoardMember, true));
        Assert.AreEqual(NullableInt32.Null, newBoardMember.ManagesDepartmentId);
        Assert.IsTrue(adapter.DeleteEntity(newBoardMember));

        newBoardMember = new BoardMemberEntity();
        // Employee's fields
        newBoardMember.Name = "Frans Bouma";
        newBoardMember.StartDate = DateTime.Now;
        newBoardMember.ManagesDepartmentId = NullableInt32.Null;    // set to NULL

        Assert.IsTrue(adapter.SaveEntity(newBoardMember, true));
        Assert.IsTrue(newBoardMember.TestOriginalFieldValueForNull(BoardMemberFieldIndex.ManagesDepartmentId));
        PredicateExpression additionalFilter = new PredicateExpression();
        additionalFilter.Add(PredicateFactory.CompareValue(BoardMemberFieldIndex.Name, ComparisonOperator.Equal, "Frans Bouma"));
        Assert.IsTrue(adapter.DeleteEntity(newBoardMember, additionalFilter));
    }
}

With .NET 2.0, this might be even smoother, but haven't tried it yet. I'll include the sourcecode of the type converter in today's build of the beta.