2016-09-14 149 views
0

我有一個存在的SQL Server數據庫。實體框架 - 生成空類

我在visual studio 2013 asp.net項目中添加了一個新的ado.net實體數據模型,並給它命名爲「DB」,模型內容爲「從數據庫生成」。

實體框架項已成功添加到項目中。 VS自動爲每個表生成一個文件和一個類,但是對於實體名稱 - 「DB」,它只創建了一個帶有註釋的文件。

這個DB.cs文件的外觀:

//------------------------------------------------------------------------------ 
    // <auto-generated> 
    //  This code was generated from a template. 
    // 
    //  Manual changes to this file may cause unexpected behavior in your application. 
    //  Manual changes to this file will be overwritten if the code is regenerated. 
    // </auto-generated> 
    //------------------------------------------------------------------------------ 

而本作例子,說明文件Person.cs(表示表格的人)的樣子:

//------------------------------------------------------------------------------ 
    // <auto-generated> 
    //  This code was generated from a template. 
    // 
    //  Manual changes to this file may cause unexpected behavior in your application. 
    //  Manual changes to this file will be overwritten if the code is regenerated. 
    // </auto-generated> 
    //------------------------------------------------------------------------------ 

    namespace Kupa_V1.Dal 
    { 
     using System; 
     using System.Collections.Generic; 

     public partial class Person 
     { 
      public Person() 
      { 
       this.Family = new HashSet<Family>(); 
       this.Family1 = new HashSet<Family>(); 
       this.Help = new HashSet<Help>(); 
      } 

      public int PersonId { get; set; } 
      public Nullable<int> FamilyId { get; set; } 
      public string FirstName { get; set; } 
      public string LastName { get; set; } 
      public System.DateTime DateOfBirth { get; set; } 
      public string TeudatZehut { get; set; } 
      public string Phone { get; set; } 
      public string Email { get; set; } 
      public string Issue { get; set; } 

      public virtual ICollection<Family> Family { get; set; } 
      public virtual ICollection<Family> Family1 { get; set; } 
      public virtual Family Family2 { get; set; } 
      public virtual ICollection<Help> Help { get; set; } 
      public virtual Work Work { get; set; } 
     } 
    } 

回答

1

是,空DB.cs文件將被生成。您需要查找的是另一個名爲DB.context.cs的文件。您可以通過擴展DB.edmx,然後在添加實體數據模型的相同項目中擴展DB.Context.tt來找到它。