c# - FluentNhibernate + 私有(private)集

标签 c# nhibernate fluent-nhibernate fluent-nhibernate-mapping

我正在使用带有私有(private)集的自动属性,而 fluentNhibernate 为我抛出一个错误...

FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail. * Database was not configured through Database method.

这是我的课:

public class MyClass
{
    public virtual int Id { get; set; }
    public virtual string PropOne { get; private set; } 
}

这是我的 map :

public class MyClassMap : ClassMap<MyClass>
{
    public MyClassMap()
    {
        Id(x => x.Id);
        Map(x => x.PropOne);
    }
}

如果我将属性更改为:

public virtual string PropOne { get; protected set; }, 

FN 工作正常。

但我读了这个主题:https://github.com/jagregory/fluent-nhibernate/wiki/Fluent-mapping 《Access Strategies》,我一直在做这个话题。我哪里错了?

我在 GitHub 上放了一个例子:https://github.com/wbaldanw/NhAccessStrategies

下面是BuildSession的代码

    Configuration = new Configuration().Configure();
        var fluentConfiguration = Fluently.Configure(Configuration)
            .Mappings(x => x.FluentMappings.AddFromAssemblyOf<MyClassMap>());
        try
        {
            NHSession = fluentConfiguration.BuildSessionFactory();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.ToString());
        }

最佳答案

我在 FluentNhibernate 项目上提出了一个问题,正确的是使用带字段的私有(private)集。如果使用 autoproperties 权利是使用非私有(private) setter。

这个工作正常:

private string name;

public string Name
{
  get { return name; }
}

关于c# - FluentNhibernate + 私有(private)集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20588293/

相关文章:

c# - 在 C# 中将二维数组归零的最快方法

performance - 为什么NHibernate会一一删除引用的对象,而不是使用外键?

fluent-nhibernate - 我可以制定包含父键名称的 Fluent NHibernate 外键约定吗?

c# - 在 nhibernate 中,无法更新子对象列表

c# - Datagrid RowDetails 未更新

c# - "Bit rate"属性是否固定在索引 28 中?

c# - 如何显示读取文件和写入数据库的进度

nhibernate - 抽象 NHibernate 标准是否有值(value)?

performance - NHibernate HQL vs CriteriaAPI vs QueryOver vs Linq。表现

c# - Nhibernate:通过<component>构建一个List<string>