FluentNhibernate +私人设置 [英] FluentNhibernate + private set

查看:104
本文介绍了FluentNhibernate +私人设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


FluentNHibernate.Cfg.FluentConfigurationException

使用private属性设置auto属性,fluentNhibernate为我输入一个错误。 :创建SessionFactory时使用了无效或不完整的配置。检查PotentialReasons集合和InnerException获取更多细节。
*数据库没有通过Database方法配置。


这是我的课程:

  public class MyClass 
{
public virtual int Id {get;组; }
公共虚拟字符串PropOne {get;私人设置





这是我的地图:

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






如果我将属性更改为:

  public virtual string PropOne {get;保护组},

FN可以正常工作

但是我读了这个话题: https://github.com/jagregory/fluent- nhibernate / wiki / Fluent-mapping 访问策略,我一直在做这个话题。我在哪里错了?



我在GitHub中添加了一个示例: https ://github.com/wbaldanw/NhAccessStrategies



下面,BuildSession的代码

  Configuration = new Configuration()。Configure(); 
var fluentConfiguration =流利.Configure(Configuration)
.Mappings(x => x.FluentMappings.AddFromAssemblyOf< MyClassMap>());
尝试
{
NHSession = fluentConfiguration.BuildSessionFactory();

catch(Exception ex)
{
Console.WriteLine(ex.ToString());


解决方案

我在FluentNhibernate项目,正确的是使用私人设置字段。如果使用autoproperties的权利是使用非私有的setter。

这工作正常:

 私人字符串名称; 

公共字符串名称
{
get {return name; }
}


I'm using auto property with private set, and fluentNhibernate throw an error for me...

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.

This is my class:

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

This is my map:

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

If I change my propertie to:

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

the FN work fine.

But I read this topic: https://github.com/jagregory/fluent-nhibernate/wiki/Fluent-mapping "Access Strategies",and I've been making just like this topic. Where I wrong?

I put an example in GitHub: https://github.com/wbaldanw/NhAccessStrategies

Below, the code of 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());
        }

解决方案

I put an issue on FluentNhibernate project, and the correct is use private set with fields. If using autoproperties right is to use non-private setter.

This work fine:

private string name;

public string Name
{
  get { return name; }
}

这篇关于FluentNhibernate +私人设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆