EntityFramework.Functions icon indicating copy to clipboard operation
EntityFramework.Functions copied to clipboard

Enum inside Entity Type

Open nickitatkach opened this issue 8 years ago • 4 comments

Hello.

I am not able to create Model Defined Function if Entity Type uses Enum inside.

How I can fix this?

Thanks.

nickitatkach avatar Aug 08 '17 09:08 nickitatkach

@nickitatkach Can you share your code?

Dixin avatar Aug 08 '17 17:08 Dixin

@Dixin Sure.

Here is Entity Type

public class ToDo
{
        [Required]
        [StringLength(128)]
        public string Id { get; set; }

        [StringLength(150)]
        public string Title { get; set; }

        public DateTime StartDate { get; set; }

        public DateTime DueDate { get; set; }

        public ToDoPriority Priority { get; set; }

        public int Progress { get; set; }
}

Here is DbFunctions

[ModelDefinedFunction(nameof(ParseDecimal), "Namespace", "cast([ToDo].[Progress] as Decimal(20,8))")]
   public static decimal ParseDecimal(this ToDo todo) => Convert.ToDecimal(todo.Progress);

Here is OnModelCreating

modelBuilder.AddFunctions<DbFunctions>()

When I change Priority type from enum to int it works fine.

nickitatkach avatar Aug 09 '17 12:08 nickitatkach

I'm having the same issue.

modelBuilder.ComplexType<ObjectContainingEnumProperty>();

Results in:

ObjectContainingEnumProperty for method MethodNameHere is not supported in conceptual model as a structural type. This can be caused by a failure to register this type as complex. For more information, see https://msdn.microsoft.com/en-us/library/gg679474.aspx

ajbrun avatar Oct 24 '17 10:10 ajbrun

Same issue, confirmed.

grammophone avatar Nov 06 '21 02:11 grammophone