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

Fluent mapping & enum properties

1 Answer 86 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Erik
Top achievements
Rank 2
Erik asked on 04 Jul 2012, 01:23 PM
Hello,

I'm getting a designer time error when i make a property enumerable:

Public Enum OrderStatus
    Unknown = 0
    Processing
    Shipped
    Delivering
    Canceled
End Enum
 
Public Class Order
 
    Private mloc_OrderId As Long
    Public Property OrderId As Long
        Get
            Return mloc_OrderId
        End Get
        Set(ByVal value As Long)
            mloc_OrderId = value
        End Set
    End Property
 
    Private mloc_OrderStatus As OrderStatus
    Public Property OrderStatus As OrderStatus
        Get
            Return mloc_OrderStatus
        End Get
        Set(ByVal value As OrderStatus)
            mloc_OrderStatus = value
        End Set
    End Property
 
    .....
 
End Class
 
Public Function GetConfiguration() As MappingConfiguration
    Dim Configuration As New MappingConfiguration(Of Order)()
    With Configuration
        .MapType(Function(p) New With {p}).WithConcurencyControl(OptimisticConcurrencyControlStrategy.Changed).ToTable("Orders")
        .FieldNamingRules.AddPrefix = "mloc_"
        .HasProperty(Function(f) f.OrderId).IsIdentity(KeyGenerator.Autoinc).HasFieldName("mloc_OrderId").WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn("OrderId").IsNotNullable().HasColumnType("bigint").HasPrecision(0).HasScale(0)
        .HasProperty(Function(f) f.OrderStatus).HasFieldName("mloc_OrderStatus").WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn("OrderStatus").IsNotNullable().HasColumnType("int").HasPrecision(0).HasScale(0)
        .....

The VS editor gives the following error:
Overload resolution failed because no accessible 'HasProperty' is most specific for these arguments:
    'Public Function HasProperty(Of TKey, TValue)(expression As System.Linq.Expressions.Expression(Of System.Func(Of Table, System.Collections.Generic.IDictionary(Of TKey, TValue)))) As Telerik.OpenAccess.Metadata.Fluent.PrimitiveDictionaryPropertyConfiguration(Of Table, TKey, TValue)': Not most specific.
    'Public Function HasProperty(expression As System.Linq.Expressions.Expression(Of System.Func(Of Table, System.Enum))) As Telerik.OpenAccess.Metadata.Fluent.PrimitivePropertyConfiguration': Not most specific.
    'Public Function HasProperty(expression As System.Linq.Expressions.Expression(Of System.Func(Of Table, Integer))) As Telerik.OpenAccess.Metadata.Fluent.PrimitivePropertyConfiguration': Not most specific.

While it states here that it should be possible:
http://www.telerik.com/help/openaccess-orm/fluent-mapping-mapping-clr-enum-support.html 

Must I do more? I do want to use explicit mapping.

Thanks,

Erik


1 Answer, 1 is accepted

Sort by
0
Serge
Telerik team
answered on 04 Jul 2012, 02:00 PM
Hello Erik, 

 The problem seems to be that the correct overload cannot be resolved. This is easier in C# given that the enum is implicitly convertable to an integer. In order to make it work you need to change your mapping code a little. Just change this expression Function(f) f.OrderStatus  to Function(f) CType(f.OrderStatus, Integer).

I also noticed you are creating your mapping configuration in your class. I want to mention that it will not be picked up if it is not a Shared function that is not returning it. 

I hope this is helpful. Do let me know should you face more trouble.
 
All the best,
Serge
the Telerik team
OpenAccess ORM Q2'12 Now Available! Get your hands on all the new stuff.
Tags
Getting Started
Asked by
Erik
Top achievements
Rank 2
Answers by
Serge
Telerik team
Share this question
or