实体框架+ BaseEntity类 [英] Entity Framework + BaseEntity class

查看:101
本文介绍了实体框架+ BaseEntity类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ID,creationDate,creationUser,modificationDate和modificationUser等常用属性的BaseEntity类。我想使用实体框架,但我不知道该怎么做。

我已经完成了数据库创建,并且我已经基于它创建了一个新的实体模型。我已经看到,对于Linq to SQL,可以指定BaseEntity,但只能使用line命令工具。我们如何处理实体框架?我是否必须手动创建BaseEntity类并从中继承生成的.cs文件中的所有类?它是否正常工作?

Hi,

I'm trying to have a BaseEntity class with common properties like ID, creationDate, creationUser, modificationDate and modificationUser. I want to use the Entity Framework, but I don't know how to do it.

I've completed the database creation and I've created a new Entity Model based on it. I've seen that for Linq to SQL, it is possible to specify a BaseEntity, but only with the line command tool. How do we do with the Entity Framework ? Do I have to manually create a BaseEntity class and inherite all the classes in the generated .cs file from it ? Is it working so ?

我有一个包含大约15个表的数据库,生成的源文件已经很大了。什么是正确的方法?我们应该创建许多模型,每个模型代表数据库的一小部分吗?我想如果DB的一部分与另一部分分开,我们可以做到,但是映射到两个不同模型的表会发生什么?

I've a database containing about 15 tables and the generated source file is quite big already. What is the correct way to proceed? Should we create many models with each one representing a smaller part of the database? I guess we could do it if one part of the DB is separated from the other part, but what happens to a table mapped on two different models?

推荐答案

你好 - 没有办法用EdmGen.exe或Designer自动指定基本实体(虽然我们正在努力使代码生成更多灵活的下一个EF版本)。但是,您当前可以使用Designer创建继承层次结构。以下是一些可能有用的资源:

演练:映射继承 - 表 - -Hierarchy

演练:映射继承 - 每个类型的表

提示12 - 选择继承策略

不确定我是否已经完全回答了您的问题,但希望有所帮助。

-Brian
Hi-

There isn't a way to automatically specify a base entity with EdmGen.exe or the Designer (although we are working to make code generation more flexible in the next EF release). However, you can currently use the Designer to create inheritance hierarchies. Here are some resources that might help:

Walkthrough: Mapping Inheritance - Table-per-Hierarchy

Walkthrough: Mapping Inheritance - Table-per-Type

Tip 12 - Choosing an Inheritance Stategy

Not sure I've exactly answered your question, but hope that helps.

-Brian


这篇关于实体框架+ BaseEntity类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆