我不確定如何準確地提出我的問題,這可能是我爲什麼無法在任何地方找到此示例的原因。我正在玩MVC4 & EF5(Web API),但我不確定如何繼續使用該模型,因爲我以前從來沒有真正需要使用它們。我正在圍繞元素週期平板做一些事情,並且我想讓它具有爲它的電子配置元素構建的列表。但是,我想根據輸入順序將其設置爲自動編號。我如何告訴EF自動遞增一個字段?基本上就像一個沒有這個限制的主鍵字段。這裏是我到目前爲止 - 我只是不知道如何着手:MVC4/EF5 /自動增量
public class Elements
{
public int ElementID { get; set; }
public string Name { get; set; }
public int AtomicNumber { get; set; }
public string Symbol { get; set; }
public virtual Categories Category { get; set; }
public virtual States State { get; set; }
public virtual Occurences Occurence { get; set; }
public virtual ICollection<Configurations> Configuration { get; set; }
}
public class Categories
{
public int CategoryID { get; set; }
public string CategoryName { get; set; }
}
public class States
{
public int StateID { get; set; }
public string StateName { get; set; }
}
public class Occurences
{
public int OccurenceID { get; set; }
public string OccurenceName { get; set; }
}
public class Configurations
{
public int ConfigurationID { get; set; }
public int Order { get; set; }
public int Value { get; set; }
}
看上面是什麼,我想是一個隨時隨地值加到Configurations.Order值從1開始,並增加每個新的「行」,但僅限於該特定的ElementID。
這有道理嗎?我在查看使用數據註釋,但我找不到任何與關鍵字段相匹配的東西,但是這會使每個訂單成爲唯一的數字 - 我不想要。我覺得我沒有正確表達這一點,因爲我一直在尋找的東西,所以這裏有一張照片!好極了!
這非常好可能是東西是從程序的角度更好。即使這些數據在藍色月亮中發生了一次變化,但我仍想盡可能通過EF做到這一點,只是讓我知道如何。
感謝提前一噸。另外,如果你看到任何其他明顯的錯誤,盡我所能讓我知道:)我很少與web開發人員一起工作,所以我確信有辦法做得更好。
謝謝。不幸的是,這正是我在閱讀EF和模型時所學到的。對於這個小項目來說,這不是太重要,但它是很好的信息。 :) – Joshua