在我的应用程序中有两个表。
tblEvents
事件ID 用户名 日期 事件类型tblEventTypes
EventTypeID 事件名称tblEvents包含我们的应用程序中发生的事件的日志。 向事件添加事件时所需的一个列是事件类型。 事件类型必须是存储在tblEventTypes中的事件类型的ID。
在我使用Entity Framework的应用程序中,我为存储过程创建了一个函数import,它将事件添加到tblEvents。 目前,我将事件类型的整数传递给函数import创建的方法。 这对我来说似乎是不可读的,因为你不知道整数意味着什么不看数据库,找到事件类型表,看看它是什么事件。
我想创建一个枚举来表示事件类型。 有没有办法创建一个基于tblEventTypes中的数据生成的动态枚举? 就像EF基于数据库中的表生成实体一样,我想基于表生成一个枚举,它是当前数据。 因此,添加一个事件类型就是向tblEventTypes添加一行,然后在EF设计器中运行更新,或者在代码中自动更新我的枚举。
In my application there are two tables.
tblEvents
EventID UserID Date EventTypetblEventTypes
EventTypeID EventNametblEvents contains a log of events that occurred in our application. One of the columns required when adding an event to the log is the event type. The event type must be the ID of an event type stored within tblEventTypes.
In my application using Entity Framework I created a function import for a stored procedure that adds events to tblEvents. Currently I pass in an integer for event type into the method created by the function import. This just seems unreadable to me as you have no idea what the integer means without looking at the database, finding the event types table, and seeing what event it was.
I would like to create an enum to represent event types. Is there a way to create a dynamic enum that is generated based on the data in tblEventTypes? Just like how EF generates entities based on tables in the database, I would like to generate an enum based off of a table and it's current data. So adding an event type would be a matter of adding a row to tblEventTypes and then running an update in the EF designer or something that would automatically update my enum in the code.
最满意答案
您不能使用EF设计器,但可以使用T4模板生成枚举。
You can't use the EF designer for that, but you could use a T4 template to generate the enum.
更多推荐
发布评论