是否可以使用 Fluent NHibernate Automapping 的私有字段约定?

发布于 2024-07-11 14:39:09 字数 386 浏览 4 评论 0原文

如何使用流畅的 NHibernate AutoPersistenceModel 映射到私有字段?

    public class A
    {
        private List<B>  myField;

        public A()
        {
            myField = new List<B>();
        }

        public IList<B> MyBs
        {
            get { return myField; }
        }
    }

AutoPersistence 模型是否有字段约定,或者我是否必须对具有字段的类使用单独的映射?

How can I map to a private field with fluent NHibernate AutoPersistenceModel?

    public class A
    {
        private List<B>  myField;

        public A()
        {
            myField = new List<B>();
        }

        public IList<B> MyBs
        {
            get { return myField; }
        }
    }

Is there a fieldconvention for the AutoPersistence model or do I have to use separate mappings for classes with fields?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我不吻晚风 2024-07-18 14:39:09

答案是:

目前还不可能。 也许我应该为它提交一个补丁......

The answer:

It's not possible yet. Maybe I should submit a patch for it...

小瓶盖 2024-07-18 14:39:09

我知道这并不是不回答自动映射,而是为了帮助那些寻找私有字段映射的人。

您现在可以使用以下代码:

public class A
{
    private List<B>  myBs;

    public A()
    {
        myField = new List<B>();
    }

    public IList<B> MyBs
    {
        get { return myField; }
    }
}

使用这样的映射

public class AMap : ClassMap<A> {
        public AMap() {
            HasMany(x => x.MyBs).Access.CamelCaseField()
        }
}

I know this is not does not answer the auto mapping, but to assist those who get this searching for private field mapping.

You can now use the following code:

public class A
{
    private List<B>  myBs;

    public A()
    {
        myField = new List<B>();
    }

    public IList<B> MyBs
    {
        get { return myField; }
    }
}

With a mapping like this

public class AMap : ClassMap<A> {
        public AMap() {
            HasMany(x => x.MyBs).Access.CamelCaseField()
        }
}
葬花如无物 2024-07-18 14:39:09

自从提出这个问题以来已经有一段时间了,但可能值得发布这个答案,以防其他人发现这个问题。

Fluent NHibernate Wiki 有一些关于 3 种可能的解决方法的信息。

It's been a while since this question was asked, but it's probably worth posting this answer in case others find this question.

The Fluent NHibernate Wiki has some information on 3 possible workarounds.

http://wiki.fluentnhibernate.org/Fluent_mapping_private_properties

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文