【发布时间】:2013-01-16 20:47:48
【问题描述】:
这是我第一次在 VS2012 中使用 EF,因为到目前为止我一直在使用 2010。我添加了实体框架模型,它添加了 2 个扩展名为 .tt 的文件,我确信 VS2010 中不存在这些文件。在其中之一下,它会生成部分类以匹配实体。但是,我已经在我的应用程序根目录下另一个名为 Entites 的手动创建的文件夹中拥有这些部分类。当它们发生冲突时,这会导致构建问题...
如何阻止它们自动生成,或者如何使它们与我手动创建的部分类一起使用? VS2012 在不询问的情况下执行此操作非常烦人,因为它破坏了我的代码!
自动生成类示例
namespace StatisticsServer
{
using System;
using System.Collections.Generic;
public partial class Statistic
{
public int StatID { get; set; }
public int CategoryID { get; set; }
public int FranchiseID { get; set; }
public double StatValue { get; set; }
}
}
手动创建类的示例
namespace StatisticsServer.Entities
{
public partial class Statistic
{
public static List<Statistic> GetStatisticsSet(int categoryID)
{
List<Statistic> statSet = new List<Statistic>();
using (var context = new StatisticsTestEntities())
{
statSet = (from s in context.Statistics where s.CategoryID == categoryID select s).ToList();
}
return statSet;
}
}
}
【问题讨论】:
-
你能举一个自动生成的类和你手动创建的类的例子吗?部分类应该一起工作,但您可能创建了重复的属性/方法。
-
用例子更新问题
-
我得到的错误是“无法将类型'System.Collections.Generic.List
'隐式转换为'System.Collections.Generic.List ”我显然可以通过在类型之前显式指定命名空间来解决这个问题,但我宁愿一开始就没有那些愚蠢的自动生成的类!
标签: asp.net entity-framework visual-studio-2012