[英]Default code generated by my EF model has errors
This is kind of a noob question, and I am actually a bit embarassed to have not been able to figure it out myself , who knew transition from LinqToSQL to EF will be fraught with nuances like this. 这是一个菜鸟问题,而我自己却无法解决这个问题,这让我有些尴尬,他知道从LinqToSQL到EF的过渡将充满这样的细微差别。
Basically all I did was 基本上我所做的就是
1> create a MusicStore SQL database using visual studio 2012 Server Explorer with only one table. 1>使用Visual Studio 2012 Server Explorer(仅一个表)创建MusicStore SQL数据库。
2> Then I added a new ADO.Net Entity Data Model
edmx
and generated it using the wizard pointing to my database in step 1. 2>然后,我添加了一个新的ADO.Net Entity Data Model
edmx
并在步骤1中使用指向我的数据库的向导生成了它。
This gave me a diagram of MusicStore table. 这给了我MusicStore表的示意图。 Now if I change Code Generation Strategy
in the properties to Default
instead of none
, then this is the code that is generated in the MusicStoreModel.Designer.cs
. 现在,如果我将属性中的Code Generation Strategy
更改为Default
而不是none
,则这是在MusicStoreModel.Designer.cs
生成的代码。
However, at public MusicStoreEntities() : base("name=MusicStoreEntities", "MusicStoreEntities")
但是,在public MusicStoreEntities() : base("name=MusicStoreEntities", "MusicStoreEntities")
I get the has some invalid arguments
. 我得到了has some invalid arguments
。
What am I missing here? 我在这里想念什么? a reference? 参考? Any help greatly appreciated. 任何帮助,不胜感激。
public partial class MusicStoreEntities : ObjectContext
{
#region Constructors
/// <summary>
/// Initializes a new MusicStoreEntities object using the connection string
///found in the 'MusicStoreEntities' section of the application
///configuration file.
/// </summary>
public MusicStoreEntities() : base("name=MusicStoreEntities", "MusicStoreEntities")
{
// Also getting a compilation error at the line below
this.ContextOptions.LazyLoadingEnabled = true;
OnContextCreated();
}
This is by design. 这是设计使然。 Please refer to the following link for Microsoft's official position: Entity Framework 5 Code Generation Strategy set to DEFAULT causes errors on all properties of entities . 请参考以下链接以了解Microsoft的官方立场: 实体框架5代码生成策略设置为DEFAULT会导致实体的所有属性出错 。
(...) The reason you are seeing these compile errors is because you are re-enabling the legacy code generation without disabling the new T4 based code generation. (...)之所以会看到这些编译错误,是因为您在不禁用新的基于T4的代码生成的情况下重新启用了旧代码生成。 This means that two sets of classes are being generated. 这意味着将生成两组类。 This page provides details on how to revert to ObjectContext code generation - http://msdn.microsoft.com/en-us/data/jj556581 . 此页面提供有关如何还原为ObjectContext代码生成的详细信息-http: //msdn.microsoft.com/zh-cn/data/jj556581 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.