gpt4 book ai didi

c# - N 休眠 3.3 : Setting the type to Ansistring in an Id for Mapping by code

转载 作者:太空宇宙 更新时间:2023-11-03 20:21:39 25 4
gpt4 key购买 nike

我正在映射以下实体:

public class PersonEntity
{
public virtual string PersonId { get; set; }

public virtual String Salutation { get; set; }
public virtual String FirstName { get; set; }
public virtual String LastName { get; set; }
public virtual DateTime Birthdate { get; set; }
}

public class PersonMap : ClassMapping<PersonEntity>
{
public PersonMap()
{
//ComponentAsId(i => i.Key, map => map.Property(p => p.PersonId, m => m.Type(NHibernateUtil.AnsiString)));

Id(i => i.PersonId, map => map.Type(???)));
Property(i => i.Salutation);
Property(i => i.FirstName);
Property(i => i.LastName);
Property(i => i.Birthdate);
}
}

正如您在注释掉的代码中看到的那样,在将组件用作 Id 时,我可以使用 NHibernateUtil 将类型设置为 AnsiString。但是我无法弄清楚在普通 Id 映射中该做什么。

我曾尝试使用 new NHibernate.Type.AnsiStringType(),但这会提示没有为其定义任何构造函数。

有什么想法吗?

最佳答案

我必须将 AnsiStringType 显式转换为 IIdentifierType 并设置长度属性。

       Id(x => x.Id,
m =>
{
m.Generator(Generators.Assigned);
m.Type((IIdentifierType)TypeFactory.GetAnsiStringType(16));
m.Length(16);
});

关于c# - N 休眠 3.3 : Setting the type to Ansistring in an Id for Mapping by code,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13116472/

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