gpt4 book ai didi

fluent-nhibernate - 使用 fluent-nhibernate 是否可以在实体内自动映射值对象?

转载 作者:行者123 更新时间:2023-12-04 09:00:53 29 4
gpt4 key购买 nike

我正在使用 Sharp 架构,并且在许多情况下都在实体中使用了值对象。这是一个明显的简单示例:

public class Person : Entity
{
protected Person(){}

public Person(string personName)
{
this.PersonName = personName;
}

public virtual string PersonName { get; protected set;}
public virtual StreetAddress MailingAddress { get; set; }
}

public class StreetAddress : ValueObject
{
protected StreetAddress(){}

public StreetAddress(string address1, string address2, string city, string state, string postalCode, string country )
{
this.Address1 = address1;
this.Address2 = address2;
this.City = city;
this.State = state;
this.PostalCode = postalCode;
this.Country = country;
}

public virtual string Address1 { get; protected set; }
public virtual string Address2 { get; protected set; }
public virtual string City { get; protected set; }
public virtual string State { get; protected set; }
public virtual string PostalCode { get; protected set; }
public virtual string Country { get; protected set; }
}

这当然会抛出:

An association from the table Person refers to an unmapped class: Project.Domain.StreetAddress
因为 AutoPersistenceModelGenerator 只包含类型为 IEntityWithTypedId<> 的类。目前尚不清楚 Sharp Architecture 期望如何实现这种常见条件。这是否必须通过无数次覆盖来处理?

最佳答案

您可以将 AutoPersistenceModelGenerator 中的 GetSetup() 方法更改为:

private Action<AutoMappingExpressions> GetSetup()
{
return c =>
{
c.IsComponentType = type => type.BaseType == typeof (ValueObject);
};
}

我将尝试获取我看到的涵盖此帖子的博文以获得信用。

关于fluent-nhibernate - 使用 fluent-nhibernate 是否可以在实体内自动映射值对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3074086/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com