实体框架不会复数我的 SQLServer 数据库
我正在使用 .NET Framework 3.5。所以我认为EF也是3.5。 我在这里看到了一些东西: EF3.5 不单一化或名字采用复数形式。
不幸的是,在 .NET 3.5 SP1 中附带的实体框架的当前版本中,我们在从数据库对模型进行逆向工程时不会尝试对名称进行单数化或复数化。
在我的 MVC2 项目中,我想编写一个 For Orders 的分部类以用于表单验证。哪个是正确的?你能推荐一些示例文件吗?
public partial class Order { ... }
public partial class Orders { ... }
.edmx 之后的 .cs 中的代码:
public partial class Questions : global::System.Data.Objects.DataClasses.EntityObject
{
/// <summary>
/// Create a new Questions object.
/// </summary>
/// <param name="questionnaireGUID">Initial value of QuestionnaireGUID.</param>
public static Questions CreateQuestions(string questionnaireGUID)
{
Questions questions = new Questions();
questions.QuestionnaireGUID = questionnaireGUID;
return questions;
}
I'm using .NET Framework 3.5. So I think the EF is also 3.5.
I saw something here: EF3.5 don't Singularize or Pluralize names.
Unfortunately in the current version of the Entity Framework, which ships in .NET 3.5 SP1, we don't make any attempt to Singularize or Pluralize names when reverse engineering a model from the database.
And in my MVC2 project, I want to code a partial class For Orders for form validation purposes. Which is correct? Can you suggest some sample files.
public partial class Order { ... }
public partial class Orders { ... }
The code from my .cs after .edmx:
public partial class Questions : global::System.Data.Objects.DataClasses.EntityObject
{
/// <summary>
/// Create a new Questions object.
/// </summary>
/// <param name="questionnaireGUID">Initial value of QuestionnaireGUID.</param>
public static Questions CreateQuestions(string questionnaireGUID)
{
Questions questions = new Questions();
questions.QuestionnaireGUID = questionnaireGUID;
return questions;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在 .edmx 模型中手动将实体名称复数化。
部分类取决于生成的实体类的名称。您可以再次检查实体模型(这次是 .cs 类),您会发现是否有
Order
或Orders生成。
编辑:
您在 edmx 中找到了
公共部分类问题
,因此如果您想为此创建验证类,则必须再次使用公共部分类问题
。如果您使用单数形式,则类不会连接,因为在这个级别,它们只是类,编译器可能不会猜测,他应该将 Question 与 Question*s* 连接起来。这些类名只是字符串,其中没有任何语义。You can pluralize enities names manually in your .edmx model.
Partial class depends on name of entity class, that is generated.You can again check entity model (this time its .cs class) and there you will find if you got
Order
orOrders
generated.Edit:
You have found
public partial class Questions
in your edmx, so if you want to create validation class to this, you must again usepublic partial class Questions
. If you would use singular form, the classes wouldn't be connected, becuase at this level, they are just classes and the compiler probably wouldn't guess, that he should connect Question with Question*s*. Those class names are just strings without any semantics inside them.