您可以在 Linq-to-SQL 中的多个实体中使用相同的 Enum 吗?
在我的持久层中,我声明了一组枚举来表示包含引用数据的表(即数据永远不会改变)。
在 Linq2SQL 中,我能够将实体属性的类型设置为枚举类型,一切都很好,但是一旦我将第二个实体的属性设置为使用相同的枚举类型,代码生成器 (MSLinqToSQLGenerator) 就会开始生成一个空的代码文件。
我认为 MSLinqToSQLGenerator 正在悄然崩溃。问题是为什么,有没有解决方法?还有其他人遇到过这个问题吗?
In my persistence layer, I've declared a load of Enums to represent tables containing reference data (i.e. data never changes).
In Linq2SQL, I am able to set the type of an entity property to an enum type and all is well, but as soon as I set a second entity's property to use the same enum type, the Code Generator (MSLinqToSQLGenerator) start generating an empty code file.
I assume that MSLinqToSQLGenerator is quietly crashing. The question is why, and are there any work-arounds? Anyone else experienced this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的枚举是否位于与 dbml 名称相同的文件中? 3.5 中存在一个错误(4.0 中已修复),冲突导致文件为空。奇怪的是,通常移动
using
指令(并右键单击;运行自定义工具)可以修复它。因此,如果您有“foo.dbml”和您自己的“foo.cs”(在同一文件夹中):
它将中断(生成一个空的 foo.designer.cs)。如果你有:
它会起作用。我不是在开玩笑。同样,将“foo.cs”重命名为“bar.cs”(然后右键单击,运行自定义工具)将修复它。
Is your enum by any chance in a file named the same as the dbml? There is a bug in 3.5 (fixed in 4.0) where conflicts cause an empty file. Oddly, usually moving the
using
directives (and right-click; run custom tool) fixes it.So if you have "foo.dbml" and your own "foo.cs" (in the same folder) with:
it will break (generate an empty foo.designer.cs). If you have:
it will work. I'm not kidding. Likewise, renaming "foo.cs" to "bar.cs" (and right-click, run custom tool) will fix it.
奇怪的是,我发现这种行为仅发生在名为“GrantType”的枚举中。一旦更改了枚举的名称,生成器就重新开始工作。
Oddly, I've discovered that this behavior only occured with an Enum named "GrantType". As soon as changed the name of the enum, the generator started working again.