我正在使用带有私有(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/