【发布时间】:2013-11-27 13:16:39
【问题描述】:
我有以下课程
public partial class ActionType
{
public System.Guid ActionTypeId { get; set; }
public string ActionTypeName { get; set; }
}
现在我想像这样使用存储在数据库中的所有 ActionType:
MyEntity entity = new MyEntity();
entity.ActionTypeId = ActionTypes.???
在这里我希望能够通过 ActionTypeName 选择 ActionTypeId。
现在我是这样做的:
public class ActionTypes
{
public static readonly Guid CustomerAdded = new Guid("36520b53-e1d0-4c96-bec8-0df85536a96b");
public static readonly Guid CustomerEdited = new Guid("732592d3-7423-4250-aa74-e10fe1e7c030");
}
我希望能够以编程方式从数据库中创建 ActionTypes,而不是自己编写值。
所以我想做这样的事情:
public class ActionTypes
{
List<ActionType> list = context.GetAllActionTypes();
foreach(ActionType type in list)
{
public static readony Guid type.ActionTypeName = type.ActionTypeId;
}
}
如何实现我的意图?
最好的问候
【问题讨论】:
-
我不确定我是否理解。
Dictionary<string, Guid>有帮助吗? -
你在这里问什么非常不清楚。您拥有的代码有效,您想要什么不同?
-
对不起,我已经编辑了问题