Problem changing a nullable date field value with self tracking poco

Posts   
 
    
Ads
User
Posts: 4
Joined: 08-Mar-2011
# Posted on: 08-Jul-2011 14:42:41   

Hi,

I'm pretty new to LLBLGen so this may have been anwered but I haven't been able to find one.

LLBLGen Pro 3.1 Entity Framework 4 Selftracking Pocos

When I try to change a nullable date value in an entity it does not change the value. (either by my code or databinding from a control)

The value before the change is nothing. After the change the value is nothing.

The code which is causing it not to change is located in the model entity class.

This is the property code

<DataMember> _ public Property Xx_Srch_Avail_From As Nullable(Of System.DateTime) Get Return _xx_Srch_Avail_From End Get Set If Not (_xx_Srch_Avail_From = Value) Then ChangeTracker.RecordOriginalValue("Xx_Srch_Avail_From",_xx_Srch_Avail_From) OnXx_Srch_Avail_FromChanging(Value) _xx_Srch_Avail_From = Value OnPropertyChanged("Xx_Srch_Avail_From") OnXx_Srch_Avail_FromChanged() End If End Set End Property

When I step through the code and try the following in the immediate window ?Not (_xx_Srch_Avail_From = Value)

I get 'Nothing' instead of a boolean value of true therefore it never enters the if statement to make the change.

This seems to only by happening with dates, everything else strings and integers work fine (I only have nullable on dates)

What can I do to rectify this?

Many thanks for your time

Ads
User
Posts: 4
Joined: 08-Mar-2011
# Posted on: 08-Jul-2011 17:15:36   

If I change the generated code for that particular property to

If Not (_xx_Srch_Avail_From.Equals(Value)) Then ........... End If

Then it works perfectly.

Changing generated code is obviously not an option.

Changing the template maybe, however as stateted I haven't been using LLBLGen for long and the thought of trawling through templates fixing this is not giving me a happy feeling for the weekend.

Other people must have had this problem before?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 09-Jul-2011 02:00:13   

I reproduced it, the value is not even set when you fetch the entity.

[TestMethod]
public void RetrieveNullableDateTimeField()
{
    var order = new Order();
    using (var context = new NWEFMSSQLSTPv31DataContext())
    {
        order = (from o in context.Orders
                    where o.OrderId == 10249
                    select o).FirstOrDefault();
    }

    // this fails
    Assert.IsTrue(order.OrderDate.HasValue);        
}

It seems like this is one of the VB.Net goodies (the C# templates work fine). I found other guys having the same problem out there: http://stackoverflow.com/questions/4206383/comparing-nullable-datetimes-in-vb-net

Indeed the workaround is to use .Equals:

        <DataMember()> _
        Public Property RequiredDate As Nullable(Of System.DateTime)
            ...
            Set(value As Nullable(Of System.DateTime))
                If Not (_requiredDate.Equals(Value)) Then
                    ...
                End If
            End Set
        End Property

We will look into this to see if a change could be made in the templates.

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 11-Jul-2011 10:22:36   

Fixed. As the change requires multiple template changes (as we moved the logic to 1 centralized method to avoid redundant code in the templates), I've packed all entity framework templates in 1 archive, which is attached

Unpack this archive in the folder: <llblgen pro installation folder>\Frameworks\Entity Framework\Templates

and do that as administrator, overwriting the existing files in that folder and subfolders.

Frans Bouma | Lead developer LLBLGen Pro
Ads
User
Posts: 4
Joined: 08-Mar-2011
# Posted on: 11-Jul-2011 10:56:11   

Hi,

I had started re-writing projects into C#, however I have just tested the new templates and the're spot on.

No need to carry on re-writing (just saved me loads of time!!!)

A quick question, now that you have this fix for the templates, how do you role it out to all your users, is it in an update or do users have to find this thread ?

Thanks a lot for the speedy fix

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 11-Jul-2011 11:27:33   

Every new release/update should hold all fixes done since the last update. So in short: all users get it.