문제

I'm working on a new project but its database already exists so i'm using EF database first approach.

I've a property named WorkflowStatus which exists in all tables and its data type is int but i need to map its type to WorkflowStatusEnum instead of Int32

So i've modified the T4 template to change the generated property type and it worked as i want but now the system doesn't work because of mismatch between the property type on the model and the generated property.

I need to know if there is an easy way to change the data type of the property on the model so the system can work fine or i've to change it manually on all entities on the model.

도움이 되었습니까?

해결책

Create IWorkflowStatus interface with only one property in it - WorkflowStatus.

In t4 add IWorkflowStatus to the signature of every entity that has property WorkflowStatus, i.e.

public partial class Order: EntityObject, IWorkflowStatus

Next create ExtentionMethod for IWorkflowStatus to work with enum in the way you'd like to.

public static void SetStatus(this IWorkflowStatus entity, WorkflowStatus status)
public static WorkflowStatus GetStatus(this IWorkflowStatus entity)

That's probably the easiest solution.

Another one is to generate a typed property in each entity with the use of T4, but leave the integer property as well.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top