Question

I am a beginner of OpenAccess.I am writing some test code according to my experience of "Linq to Sql"

I try to map a allow null int field to "NullAble" enum type property, but fail.

In the Visual Designer of VS.Net, if I set the "Nullable" property to "true" and "Type" property to "MyEnum"("MyEnum" is the enum I defined) to the property in the domain class, the error below will be returned when I compile the project.

The type for member with name "MyEnum" of "MyClass" presistent class is not a valid mapping for its column.

If I set the "Nullable" property to "false" and "Type" property to "MyEnum?" to the property in the domain class, the compiling pass, but the error below will be returned when fetch data from database at runtime.

Type converter initialization failed. The converter with name 'IntConverter' does not convert from CLR type 'System.Nullable`1[[Model.MyEnum, Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' to SQL type 'int'.

But in "Linq to Sql", "NullAble" enum type property can be mapped into a class and work fine.

Thank you for any help in advance!

Was it helpful?

Solution

Unfortunately it seems that the Nullable Enums are not currently supported but this issue is already addressed and you could find it updated in a future version of Telerik OpenAccess ORM.

As a workaround you could create a wrapper property in a partial class of your Domain Class for getting and setting the Enum properly.

You could achieve this by following the steps below: 1) Change the type of the Domain Class Property to "int", set its Nullable setting to "true" and its Access Modifier to "private". 2) Create a partial class of the entity containing the Nullable enum. 3) Add a wrapper property and implement its getter and setter as below:

public MyEnum? MyEnumWrapper
{
    get
    {
        if (this.MyEnum.HasValue)
        {
            return (MyEnum)this.MyEnum.Value;
        }

        return null;
    }
    set
    {
        this.MyEnum = (int?)value;
    }
}

Regarding the mapping error that you are getting - it is a part of the OpenAccess ORM validation framework which is meant to warn you about possible inconsistencies in the model and it does not mean that your project is not buildable and it will also be fixed implementing the nullable enum support.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top