2012-07-06 25 views
1

我對這個主題有所瞭解(代碼第一次開發)。我想要做asp.net默認用戶表和我的班級(一對一)之間的關係。ASP.NET MVC關係codefirst和現有的數據庫表?

  1. 這是可能的。
  2. 如果這是可能的。我該怎麼辦。我應該寫用戶類嗎?或任何方式。

你能否給我一個出發點?我的課如下。

public class Customer 
{ 
    [Key] 
    public int customer_id { get; set; } 
    public string customer_name{ get; set; } 
    public string user_id 

    public virtual User User{ get; set; } 
} 

我希望,我已經解釋:)

感謝。

回答

1

如果我不能正確對待 - 是的,你可以在你的代碼中編寫所有你想使用的類,即使它存在於數據庫中。這裏有一些教程,也許它可以幫助你http://codefirst.codeplex.com/

+0

+1。但它聽起來像它可以做的。我不應該寫。應該有一個選項。因爲,我可以在我的項目中獲得asp.net默認表模型。我可以使用它。你可以看看這個:http://stackoverflow.com/questions/6021135/ef-code-first-1-to-1-optional-relationship – 2012-07-06 06:25:39

+0

看看這裏,如果你想與你的數據庫和asp mvc會員制作相關的數據庫它推薦幫助的http://stackoverflow.com/questions/6447313/how-do-i-integrate-membership-tables-with-entity-framework-asp-net – 2012-07-06 06:45:31

+0

我想我無法解釋:)對不起的問題是我的解釋。我可以在不寫入的情況下使用User類。我很抱歉,如果我沒有看到一個完全相同的例子,我不會理解。感謝您的關注。 – 2012-07-06 07:29:16