nhibernate بطلاقة: يتم تعيين التعداد في المفتاح المركب إلى int عندما أحتاج إلى سلسلة
-
21-09-2019 - |
سؤال
بشكل افتراضي ، يتمثل سلوك FNH في تعيين التعداد إلى سلسلةها في DB.
ولكن أثناء تعيين التعداد كجزء من مفتاح مركب ، يتم تعيين الخاصية على أنها int.
على سبيل المثال
في هذه الحالة
public class Address : Entity
{
public Address() { }
public virtual AddressType Type { get; set; }
public virtual User User { get; set; }
حيث adderstype من
public enum AddressType
{
PRESENT, COMPANY, PERMANENT
}
رسم الخرائط FNH كما
mapping.CompositeId().KeyReference(x => x.User, "user_id").KeyProperty(x => x.Type);
ينتج عن خلق مخطط هذا الخرائط
create table address (
Type INTEGER not null,
user_id VARCHAR(25) not null,
و HBM كما
<composite-id mapped="true" unsaved-value="undefined">
<key-property name="Type" type="Company.Core.AddressType, Company.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<column name="Type" />
</key-property>
<key-many-to-one name="User" class="Company.Core.CompanyUser, Company.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<column name="user_id" />
</key-many-to-one>
</composite-id>
حيث ينبغي إنشاء addressType كـ
type="FluentNHibernate.Mapping.GenericEnumMapper`1[[Company.Core.AddressType,
كيف يمكنني تعليمات FNH إلى mappit باعتبارها خريطة عامة تعداد السلسلة الافتراضية؟
المحلول
لا تنتمي إلى StackOverflow