为什么有些实体获得FK对象和FK id字段,其他实体只获得FK对象? [英] Why do some entities get FK objects and FK id fields, others only get FK objects?

查看:77
本文介绍了为什么有些实体获得FK对象和FK id字段,其他实体只获得FK对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在生成现有sql架构的ado.net实体数据模型。某些对象只有一个关系对象作为属性。某些对象将关系对象都作为属性,但在这种情况下归属的标识也是对象的属性。例如:在一次案例中,我有一个与公司存在关系的用户表(用户必须属于公司)。用户实体只包含一个公司属性,在这种情况下,int companyId不会作为User对象的一部分公开,尽管这是数据库中的实际内容。我有另一个名为Orders的表,它有一个userId列。生成的Orders对象具有User作为属性和userId。为什么有些关系而不是其他?什么控制了这种行为?两个关系在数据库中设置相同,并且联接字段是PK的整数标识列。

谢谢,罗杰

I am generating an ado.net entity data model of an existing sql schema. Some objects have only a relationship object as a property. Some objects have both the relationship object as a property, but the identity filed in this case is also a property of the object. For instance: in once case I have a user table with an existing relationship to company ( a user must belong to a company ). The User entity is crated with simply a Company property on it, and the int companyId in this case, is not exposed as a part of the User object, though that is what is actually in the database. I have another table called Orders, and it has a userId column. The generated Orders object has both the User as a property, and userId. Why some relationships and not other? What controls this behavior? Both relationships are setup the same in the database, and the joinging fields are PK's, integer identity columns.

Thanks,
Roger

推荐答案

如果在数据库中,ForeignKey也是表PrimaryKey的一部分,则应在实体中同时获得FKProperty和FKReference属性。

如果ForeignKey不是PrimaryKey的一部分,则这是不是这样的。

这至少是.NET 3.5 SP1中的行为。

在.NET 4.0中,这种行为已经发生了变化,默认情况下,无论数据库中的所有ForeignKeys是否都是PrimaryKey的一部分,它们都将获得FKProperties。

这是否解释你所看到的内容?

希望这有助于干杯
亚历克斯
If in the database a ForeignKey is part of the tables PrimaryKey too, you should get both a FKProperty and a FKReference property in your entity.

If the ForeignKey is not part of the PrimaryKey this is not the case.

This at least is the behavior in .NET 3.5 SP1.

This behavior has changed in .NET 4.0, where by default you will get FKProperties for all ForeignKeys in the database whether they are part of the PrimaryKey or not.

Does this explain what you are seeing?

Hope this helps
Cheers
Alex


这篇关于为什么有些实体获得FK对象和FK id字段,其他实体只获得FK对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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