我創建了一個模型實體框架與長列名創建數據庫
public class Moo
{
public Int32 MooId { get; set; }
public string Description { get; set; }
public City CityIdFrom { get; set; }
public Int32 Weight { get; set; }
}
和
public class City
{
public Int32 CityId { get; set; }
public string Name { get; set; }
}
和我的Global.asax.cs
寫道public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
System.Data.Entity.Database.SetInitializer(
new System.Data.Entity.DropCreateDatabaseAlways<DbConnection>());
...
高於預期
簡而言之 - 我follo在here的教程。
不過,我得到一個數據庫表哞的列創建如下:
[MooId]
,[Description]
,[Weight]
,[CityIdFrom_CityId]
但是,因爲它是在本教程中,我希望這一下爲:
[MooId]
,[Description]
,[Weight]
,[CityIdFrom]
是什麼生成器添加不必要的原因_CityId? (所有關係表中的列都一樣)我很確定必須有一個設置,但我覺得很難說出我的問題。
我已經添加了'System.ComponentModel.DataAnnotations.Schema.Column(「Aaa」)] public City CityIdFrom {get;組; }'但它沒有改變任何東西:(我可能只是盲目的,我也在執行前刪除了表,所以我確信它重新創建表。 –