首先,我是 MVC 的新手。
我有一个 Project 表,其中包含 ProjectID、ProjectNumber 和 ProjectDescription 字段。ProjectId 是 int 类型的 entityKey,ProjectNumber 需要是唯一约束。
如何在实体框架 6.1.3 中执行此操作?
在我的项目课上我有
public int ProjectID { get; set; }
[Index(IsUnique = true)]
[StringLength(200)]
public string ProjectNumber { get; set; }
public string ProjectDescription { get; set; }
Run Code Online (Sandbox Code Playgroud)
当我从模型生成数据库时,该字段在数据库中未设置为唯一。
我究竟做错了什么?
c# asp.net-mvc entity-framework ef-database-first entity-framework-6
我写了一个返回的方法
List<KeyValuePair<CommandType, List<string>>>
Run Code Online (Sandbox Code Playgroud)
CommandType
属于Type enum
public enum CommandType
{
Programmed,
Manual
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,KeyValuePair
有时候的值是一个enum
,有时它是一个字符串列表,但我需要将所有内容保存KeyValuePair
在一个列表中.
目前,我将值作为keyvaluepair中的对象传递,当方法返回列表并通过它迭代时,基于键,我将值转换回其原始类型.
有没有更好的方法来实现这个?
这是一个示例代码
public enum ProgrammedCommands
{
Sntp,
Snmp,
}
private List<KeyValuePair<CommandType, object>> GetCommandsFromTemplate(string[] templateLines)
{
var list = new List<KeyValuePair<CommandType, object>>();
if (templateLines != null)
for (int lineIndex = 0; lineIndex < templateLines.Length; lineIndex++)
{
if (templateLines[lineIndex].Contains("!*") && templateLines[lineIndex].Contains("*!"))
{
KeyValuePair<CommandType, object> ProgrammedSetting;
List<string> programmedCommandList;
if (templateLines[lineIndex].Contains("SNTP - SNTP Server Commands"))
{
ProgrammedSetting = new KeyValuePair<CommandType, object>(CommandType.Programmed, ProgrammedCommands.Sntp);
list.Add(ProgrammedSetting); …
Run Code Online (Sandbox Code Playgroud)