This is a migrated thread and some comments may be shown as answers.

VEnhance errors with Nullable user-defined structure

3 Answers 110 Views
Design Time (Visual Designer & Tools)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Adam
Top achievements
Rank 1
Adam asked on 20 Mar 2009, 08:52 AM
Hi,

    I have a user-defined structure for Time which wraps a DateTime field. It behaves properly i.e. it builds, reads and writes to the database. VEnhance throws an error when I declare a Nullable Time, which I would expect to work, can anyone guide me?

C:\Dev\Products\Testbed\Deliverables\Domain\obj\Debug\MSW.MAPS.Testbed.Domain.dll(-1,-1): OpenAccess Enhancer error 0: Unsupported field-type 'System.Nullable`1[MSW.Time]' found for field 'aNullableTime' of class 'MSW.MAPS.Testbed.Domain.CountryExample'. (Unsupported value type 'System.Nullable`1[[MSW.Time, MSW.MAPS.Framework, Version=2.3.3366.15159, Culture=neutral, PublicKeyToken=null]]'. The type is not marked as [Persistent].)

Here's the usage of Time, (deliberately trimmed down to highlight the point):

using

 

Telerik.OpenAccess;

 

 

 

 

namespace

 

MSW.MAPS.Testbed.Domain {

 

 

 

[

Persistent]

 

 

 

public partial class CountryExample {  

 

 

 

 

private Time someTime;  

 

private Time? aNullableTime;

  

 

internal CountryExample() { }

[

FieldAlias("someTime")]

 

 

public Time SomeTime {

 

    get { return someTime; }

 

    set { someTime = value; }

}

[

FieldAlias("aNullableTime")]

 

 

 

public Time? ANullableTime {

 

 

    get { return aNullableTime; }

 

 

    set { aNullableTime = value; }

}

}

}

 



Here's the source code for Time:

using

 

System;

 

 

using

 

System.Collections.Generic;

 

 

using

 

System.Linq;

 

 

using

 

System.Text.RegularExpressions;

 

 

 

using Telerik.OpenAccess;

 

 

 

 

namespace

 

MSW {

 

 


[
Serializable]

 

 

[

Persistent]

 

 

 

public struct Time : IFormattable {

 

 

    private DateTime data; 
    
public Time(int hour, int minute, int second) : this(new DateTime(1900, 1, 1, hour, minute, second)) {} 
    
public Time(DateTime dateTime) {data = dateTime;}

 

 

    public int Hour { get { return Data.Hour; } } 

 

    public int Minute { get { return Data.Minute; } }

 

    public int Second { get { return Data.Second; } } 

 

    //Allows OpenAccess to compile - do not use, value-types should be immutable.

     

internal DateTime Data {

 

 

        get { return data; }

 

        set { data = value; }

 

    }

 

 

 

    public override string ToString() {return Data.ToLongTimeString();}

 

 

    public string ToString(string format, IFormatProvider formatProvider) { return Data.ToString(format, formatProvider); } 

 

 

    public string ToXmlString() { return Data.ToString(Second != 0 ? "HH:mm:ss" : "HH:mm"); }

 

    
    public
override bool Equals(object obj) { 
        
if (obj == null) return false;

        

if (this.GetType() != obj.GetType()) return false;

 

        

return Data.Equals(((Time)obj).Data);

 

    }

 

 

    public override int GetHashCode() {  return Data.GetHashCode(); }

 

 

 

 

 

 

 

}

}



TIA,
Adam

3 Answers, 1 is accepted

Sort by
0
Jan Blessenohl
Telerik team
answered on 20 Mar 2009, 05:12 PM
Hi Adam,
Nullable structs are not supported. The struct fields are mapped to additional columns in the same table. We can not decide if the complete struct is null or only the containing fields. Please make the struct fields nullables instead.

Kind regards,
Jan Blessenohl
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Peter
Top achievements
Rank 1
answered on 15 Apr 2009, 09:51 AM
Jan,

We understand the point, but could you please consider allowing nullable user-defined structs when at least one of the underlying fields is not nullable (ie when you can decide whether it's the whole struct or just a field that's null)?  For us, it would be sufficient to allow nullable if all the fields were not nullable (and/or have metadata telling OpenAccess what to do).
[It may just be my take on when to use structs, but I struggle to come up with scenarios where I'd use a struct with nullable fields I really can't think of a case where I'd use a struct with all nullable fields. (I guess string fields are the awkward case - I might not allow a null, but OpenAccess couldn't tell.)]

What we're trying to do is implement a suite of standard value types for our domain that behave like the .NET framework's built-in ones.  We can work around this 'no nullable user-defined structs' limitation - we're currently using a pair of structs in each case: one 'ordinary' and one 'nullable' - but it's awkward and has a broad impact that I'd prefer to avoid.

Also, these structs are strict value types (ie immutable).  So, we originally implemented them so that the fields were only set in the constructor (they should be marked as readonly, but I didn't expect that to work with OpenAccess).  However, VEnhance couldn't handle that code and was only happy when we added setter properties (deduced from the examples).  That's open to misuse, so could you please also look at supporting immutable user-defined structs (ie with nothing that changes the fields outside the constructor).

Best regards
Peter
0
Jan Blessenohl
Telerik team
answered on 28 Apr 2009, 12:14 PM
Hello Peter,
I have made an example for you, the way the struct is stored is what we would do internally if we would support nullable structs.

The additonal properties are only for linq support, if you use oql you do not need them.

I have no idea how many nullable structs you have. If there are only a few this solution might work for you.

Sincerely yours,
Jan Blessenohl
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Design Time (Visual Designer & Tools)
Asked by
Adam
Top achievements
Rank 1
Answers by
Jan Blessenohl
Telerik team
Peter
Top achievements
Rank 1
Share this question
or