【问题标题】:Entity framework - generates empty class实体框架 - 生成空类
【发布时间】:2016-09-14 12:24:30
【问题描述】:

我有一个现有的 SQL Server 数据库。

我在 Visual Studio 2013 asp.net 项目中添加了一个新的 ado.net 实体数据模型,并将其命名为“DB”,模型内容为“从数据库生成”。

实体框架项已成功添加到项目中。 VS 自动为每个表生成了一个文件和一个类,但是对于实体名称-“DB”,它只创建了一个带有 cmets 的文件。

这就是 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(代表表格 Person)的外观:

    //------------------------------------------------------------------------------
    // <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; }
        }
    }

【问题讨论】:

    标签: c# asp.net entity-framework


    【解决方案1】:

    是的,将生成一个空的DB.cs 文件。您需要查找的是另一个名为DB.context.cs 的文件。您可以通过扩展 DB.edmx,然后在添加实体数据模型的同一项目中扩展 DB.Context.tt 来找到它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-14
      • 2012-12-17
      • 1970-01-01
      相关资源
      最近更新 更多