学习011-08-01 Key Properties(关键属性)

Key Properties(关键属性)

One of the XAF’s functions is managing a database via an ORM tool. Dealing with the database assumes that each object has a property that allows you to distinguish an object among other objects of the same type. In relational databases, such property is called a Unique key (primary key or a key). Each business class you create with an ORM tool must have a key property that will be used as a database unique key. Key property implementation differs, depending on the specific data access technology you use.
XAF的功能之一是通过ORM工具管理数据库。处理数据库假定每个对象都有一个属性,允许您在相同类型的其他对象中区分对象。在关系数据库中,这种属性称为唯一键(主键或键)。您使用ORM工具创建的每个业务类都必须有一个键属性,该属性将用作数据库唯一键。键属性实现不同,取决于您使用的特定数据访问技术。

Entity Framework (EF)(实体框架(EF))

When using EF, you can implement a key property by one of the following ways.
使用EF时,您可以通过以下方式之一实现键属性。

  • Implement a property named “Id”
    实现一个名为“Id”的属性
  • Implement a property that combines the class name and “Id”, such as “ContactId” (assuming that your class name is “Contact”)
    实现一个结合类名和“Id”的属性,例如“ContactId”(假设你的类名是“联系”)
  • Decorate any property with the Key Attribute
    使用Key属性装饰任何属性
  • Inherit your class from the DevExpress.Persistent.BaseImpl.EF.BaseObject class that has the Guid key property.
    从具有Guid键属性的DevExpress. Persit.BaseImpl.EF.BaseObject类继承您的类。

For detailed information, refer to the Keys Microsoft article.
有关详细信息,请参阅Keys Microsoft文章。

eXpress Persistent Objects (XPO)(eXpress持久对象(XPO))

In most XPO cases, you needn’t be concerned with the key property, because usually it is already implemented in a class that is used as the base for your own XPO business class. Refer to the Base Persistent Classes article for more information about different base classes to inherit from and their key properties.
在大多数XPO情况下,您不必关心键属性,因为通常它已经在用作您自己的XPO业务类的基础的类中实现。有关要继承的不同基类及其键属性的更多信息,请参阅基础持久类文章。

If you need to implement your own key property, inherit your new class from one of the Base Persistent Classes without a key (XPLiteObject, XPBaseObject or XPCustomObject), implement a key property manually, then decorate it with the KeyAttribute.
如果您需要实现自己的键属性,从没有键的基本持久类(XPLiteObject、XPBaseObject或XPCustomObject)之一继承您的新类,手动实现键属性,然后使用密钥属性装饰它。

Note
We do not recommend implementing composite or compound keys for new databases. While it is possible to design persistent classes for legacy databases with composite keys in certain scenarios, it is always better to modify the database schema to avoid this as using composite keys imposes some limitations on the default functionality. Refer to the How to create a persistent object for a database table with a compound key KB article to learn more. If you use compound keys in an ASP.NET Web Forms application, decorate the struct key property with the TypeConverterAttribute as described in the StructTypeConverter article. Also, note that the user-friendly URL mechanism does not support composite keys. Implement a custom ViewUrlManager to support them.
我们不建议为新数据库实现复合键或复合键。虽然在某些情况下可以为具有复合键的遗留数据库设计持久类,但最好修改数据库模式以避免这种情况,因为使用复合键会对默认功能施加一些限制。请参阅如何为具有复合键的数据库表创建持久对象KB文章以了解更多信息。如果您在ASP.NETWeb窗体应用程序中使用复合键,请使用TypeConverterAttribute装饰struct键属性,如structTypeConverter文章中所述。此外,请注意用户友好的URL机制不支持复合键。实现自定义ViewUrlManager以支持它们。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

汤姆•猫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值