EF用于将类映射到数据库表的逻辑 [英] Logic used by EF to map classes to database tables

查看:166
本文介绍了EF用于将类映射到数据库表的逻辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在创建对象类时看到的一种常见逻辑是,开发人员经常将类按1:1关联映射到他们的数据库表.
例如,如果我的数据库有3个表:

Table_a,Table_b和Table_c,
然后,我可以创建3个对象类,例如Class_a,Class_b和Class_c,每个类都具有与一个特定表对应的字段.

现在,从我对EF的了解中,当您向EF模型提供数据库时,它将为您创建类和DAL,但其映射逻辑不一定像上面那样为1:1.我认为它以某种方式将多个表中的字段组合到一个类中,这样,即使所有表都正确正确地表示出来,也可以得到很少数量的对象类,而数据库中的表数量却很少.

这种映射逻辑是否可以通过考虑与外键关系相关的表并将它们组合到同一个类中,而将不相关的表保留在其他类中来工作?创建对象类时,仅需要考虑外键关系吗?还是这样做有其他逻辑?我可以手动执行EF吗?

A common logic that I see when making object classes is that developers often map classes on a 1:1 assosiation to their DB tables.
For ex, if my DB has 3 tables:

Table_a, Table_b and Table_c,
then, I can create 3 object classes, like Class_a, Class_b and Class_c, with each class having fields corrosponding to one particular table.

Now, from what I read about EF, when you provide a DB to an EF model, it creates the classes and DAL for you, but its mapping logic is not necessarily 1:1 like the above. I think that it somehow combines fields from multiple tables into one class, so that you can end up with fewre number of object classes that the number of tables in your DB, even though all your tables are represented properly and correctly.

Does this mapping logic work by considering tables related by foreign key relationships and combining these into same class, while keeping unrelated tables in other class? Is the foreign key relation the only thing needed to be considered when creating object classes? Or is there some other logic of doing this? Can I manually do what EF does?

推荐答案

开始! [< ^ ] 开始! [
Go![^]Go![^]Go![^]


这篇关于EF用于将类映射到数据库表的逻辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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