2013-03-07 146 views
0

我正在用c#做asp.net中的項目作爲語言和ms sql server express。我有這麼爲止四,模型類:從模型類生成數據庫

第一:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 

namespace WerIstWo.Models 
{ 
    public class Benutzer 
    { 
     //Eigenschaften 
     private int benutzerid, gruppenid, urlaubstageinsgesamt, urlaubstagegenommen, urlaubstagerest; 
     private string titel, bezeichnung, vorname, nachname, geburtsdatum, geburtsort, 
      nationalitaet, strasse, hausnummer, plz, ort, land, mobil, fax, festnetz, email, 
      homepage, benutzerart, status, benutzername, passwort;  
     List<Gruppe> gruppen; 

     //Properties 
     public int BenutzerID 
     { 
      get { return this.benutzerid; } 
      set { this.benutzerid = value; } 
     } 
     public int GruppenID 
     { 
      get { return this.gruppenid; } 
      set { this.gruppenid = value; } 
     } 
     public int UrlaubstageInsgesamt 
     { 
      get { return this.urlaubstageinsgesamt; } 
      set { this.urlaubstageinsgesamt = value; } 
     } 
     public int UrlaubstageGenommen 
     { 
      get { return this.urlaubstagegenommen; } 
      set { this.urlaubstagegenommen = value; } 
     } 
     public int UrlaubstageRest 
     { 
      get { return this.urlaubstagerest; } 
      set { this.urlaubstagerest = value; } 
     } 
     public string Titel 
     { 
      get { return this.titel; } 
      set { this.titel = value; } 
     } 
     public string Bezeichnung 
     { 
      get { return this.bezeichnung; } 
      set { this.bezeichnung = value; } 
     } 
     public string Vorname 
     { 
      get { return this.vorname; } 
      set { this.vorname = value; } 
     } 
     public string Nachname 
     { 
      get { return this.nachname; } 
      set { this.nachname = value; } 
     } 
     public string Geburtsdatum 
     { 
      get { return this.geburtsdatum; } 
      set { this.geburtsdatum = value; } 
     } 
     public string Geburtsort 
     { 
      get { return this.geburtsort; } 
      set { this.geburtsort = value; } 
     } 
     public string Nationalitaet 
     { 
      get { return this.nationalitaet; } 
      set { this.nationalitaet = value; } 
     } 
     public string Strasse 
     { 
      get { return this.strasse; } 
      set { this.strasse = value; } 
     } 
     public string Hausnummer 
     { 
      get { return this.hausnummer; } 
      set { this.hausnummer = value; } 
     } 
     public string PLZ 
     { 
      get { return this.plz; } 
      set { this.plz = value; } 
     } 
     public string Ort 
     { 
      get { return this.ort; } 
      set { this.ort = value; } 
     } 
     public string Land 
     { 
      get { return this.land; } 
      set { this.land = value; } 
     } 
     public string Mobil 
     { 
      get { return this.mobil; } 
      set { this.mobil = value; } 
     } 
     public string Fax 
     { 
      get { return this.fax; } 
      set { this.fax = value; } 
     } 
     public string Festnetz 
     { 
      get { return this.festnetz; } 
      set { this.festnetz = value; } 
     } 
     public string Email 
     { 
      get { return this.email; } 
      set { this.email = value; } 
     } 
     public string HomePage 
     { 
      get { return this.homepage; } 
      set { this.homepage = value; } 
     } 
     public string Benutzerart 
     { 
      get { return this.benutzerart; } 
      set { this.benutzerart = value; } 
     } 
     public string Status 
     { 
      get { return this.status; } 
      set { this.status = value; } 
     } 
     public string Benutzername 
     { 
      get { return this.benutzername; } 
      set { this.benutzername = value; } 
     } 
     public string Passwort 
     { 
      get { return this.passwort; } 
      set { this.passwort = value; } 
     } 

     //Konstruktor 
     public Benutzer() 
     { 

     } 
    } 
} 

二:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 

namespace WerIstWo.Models 
{ 
    public class Gruppe 
    { 
     //Eigenschaften 
     private int gruppenid; 
     private string bezeichnung; 
     private int anzahlmitglieder; 

     //Properties 
     public int GruppenID 
     { 
      get { return this.gruppenid; } 
      set { this.gruppenid = value; } 
     } 
     public string Bezeichnung 
     { 
      get { return this.bezeichnung; } 
      set { this.bezeichnung = value; } 
     } 
     public int AnzahlMitglieder 
     { 
      get { return this.anzahlmitglieder; } 
      set { this.anzahlmitglieder = value; } 
     } 

     //Konstruktor 
     public Gruppe() 
     { 

     } 
    } 
} 

三:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 

namespace WerIstWo.Models 
{ 
    public class Kalender 
    { 
     //Eigenschaften 
     private int kalenderid; 
     private int gruppenid; 
     private int benutzerid; 
     private string art; 

     //Properties 
     public int KalenderID 
     { 
      get { return this.kalenderid; } 
      set { this.kalenderid = value; } 
     } 
     public int GruppenID 
     { 
      get { return this.gruppenid; } 
      set { this.kalenderid = value; } 
     } 
     public int BenutzerID 
     { 
      get { return this.benutzerid; } 
      set { this.benutzerid = value; } 
     } 
     public string Art 
     { 
      get { return this.art; } 
      set { this.art = value; } 
     } 

     //Konstruktor 
     public Kalender() 
     { 

     } 
    } 
} 

和第四:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 

namespace WerIstWo.Models 
{ 
    public class KalenderEintrag 
    { 
     //Eigenschaften 
     private int kalendereintragid; 
     private int kalenderid; 
     private string art; 
     private string datum; 
     private string status; 
     private string kommentar; 

     //Properties 
     public int KalendereintragID 
     { 
      get { return this.kalendereintragid; } 
      set { this.kalendereintragid = value; } 
     } 
     public int KalenderID 
     { 
      get { return this.kalenderid; } 
      set { this.kalenderid = value; } 
     } 
     public string Art 
     { 
      get { return this.art; } 
      set { this.art = value; } 
     } 
     public string Datum 
     { 
      get { return this.datum; } 
      set { this.datum = value; } 
     } 
     public string Status 
     { 
      get { return this.status; } 
      set { this.status = value; } 
     } 
     public string Kommentar 
     { 
      get { return this.kommentar; } 
      set { this.kommentar = value; } 
     } 

     //Konstruktor 
     public KalenderEintrag() 
     { 

     } 
    } 
} 

我閱讀這些教程遠遠得到這個:

http://webproject.scottgu.com/csharp/Data/Data.aspx
http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application

從我個人理解,我需要4個步驟,以生成模型類數據庫:

創建模型
創建上下文類
創建初始化程序
運行應用程序 - > db生成

但有沒有可能做到這一點沒有初始化,或者甚至沒有上下文類?我認爲只是讓我只根據我的四個模型類生成一個數據庫?或者上下文和初始化類是必需的?

謝謝!

enter image description here

回答

0

如果您使用腳手架,那麼這將只要你沒有任何許多一對多的關係產生的一切。你可以檢查這個網站閱讀腳手架http://blog.stevensanderson.com/2011/01/13/scaffold-your-aspnet-mvc-3-project-with-the-mvcscaffolding-package/

+0

謝謝,我已經建立了mvc腳手架......但我仍然有一個問題,我得到一個錯誤:Invoke-Scaffolder:「找不到對應於控制器的模型類型稱爲'Benutzer'。嘗試提供一個-ModelType參數值「我認爲它無法找到我的模型類,它在一個額外的模型文件夾。 – LeonidasFett 2013-03-07 13:40:35

+0

你可以發佈你的項目的文件夾/文件目錄樹的截圖嗎? – SOfanatic 2013-03-07 13:56:59

+0

好吧,我發佈了它。 – LeonidasFett 2013-03-07 14:08:34