Dixin / EntityFramework.Functions

EntityFramework.Functions library implements Entity Framework code first support for stored procedures (with single result type, multiple result types, output parameter), table-valued functions (returning entity type, complex type), scalar-valued functions (composable, non-composable), aggregate functions, built-in functions, niladic functions, and model defined functions.
https://weblogs.asp.net/Dixin/EntityFramework.Functions
MIT License
79 stars 27 forks source link

Enum inside Entity Type #26

Open nickitatkach opened 7 years ago

nickitatkach commented 7 years ago

Hello.

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

How I can fix this?

Thanks.

Dixin commented 7 years ago

@nickitatkach Can you share your code?

nickitatkach commented 7 years ago

@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.

ajbrun commented 6 years ago

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

grammophone commented 2 years ago

Same issue, confirmed.