English 中文(简体)
很少有人问到Nhibernate & fluent nhibernate
原标题:Few questions about nhibernate & fluent nhibernate

我有两个问题。

  1. I been reading in nhibernate beginners guide 3 about using auto mapper with fluent. I read about this before(and I use auto mapper in my project already) however I am still not sure about a couple things.

当你需要像诺尔(No.Null)()那样做,或不得不花一定时间,或反之。 你们如何建立这些联系? 你们不得不为有这些环境的每一种财产建立自动测绘台? 是否有这种违约的目的?

  1. I also been reading about common mistakes and one mistake was talking about when you need readonly. I am actually suffering from this problem and had to make a fix that I was never that happy about.

从阅读这段话后,我很想知道,是否明智地绘制了两幅我只读的那几类地图。

Say I have this

   public PlanMap()
        {
            Table("Plans");
            Id(x => x.Id);

            Map(x => x.Name).Not.Nullable().NvarcharWithMaxSize();
            Map(x => x.Description).Not.Nullable().NvarcharWithMaxSize();
            Map(x => x.Price).Not.Nullable();
            Map(x => x.Discount).Not.Nullable();
            Map(x => x.LengthInMonths).Not.Nullable();

            References(x => x.Role).Not.Nullable();
            HasMany(x => x.Students).Cascade.All();

        }

这样做是明智的。

    public ReadOnlyPlanMap()
    {
        Table("Plans");


        ReadOnly();
        SchemaAction.None();


        Id(x => x.Id);
        Map(x => x.Name).Not.Nullable().NvarcharWithMaxSize();
        Map(x => x.Description).Not.Nullable().NvarcharWithMaxSize();
        Map(x => x.Price).Not.Nullable();
        Map(x => x.Discount).Not.Nullable();
        Map(x => x.LengthInMonths).Not.Nullable();

        References(x => x.Role).Not.Nullable();
        HasMany(x => x.Students).Cascade.All();

    }

然后,当我不使用其他地图时,我需要阅读吗? 我认为这是错误的唯一东西是重复法。 我不敢肯定,我是否能够利用遗产或东西来解决这个问题。

3. 。 我在书中读到,它建议不要在你的数据库中使用“阿托特”加固办法,而是在原地使用一个hi子处理。

In the book it says if you did something like session.Save(object); it would actually go and contact the server and this would break the unit of work. Does this happen when "auto" incrementing is set on the database? I never saw evidence of that happening and actually I had to commit a record before I would actually see the id.

当你使用hi-lo时,哪类数据是你的一栏? 我通常用墨水加固。 难道我还是用了吗?

  1. 最后,从几个例子开始 我看到,他们通常把自己的PK财产当作这样的财产。

    public virtual int Id { get; private set; }
    

然而,在书本中,我不断看到

    public virtual int Id { get; set; }

我认为,使用私人套是阻止人们为科索沃警察部队自食其力的途径。

最佳回答

You would have better luck getting all of your questions answered if you broke them up into separate questions, but I ll address a couple of your questions anyway:

<>Automapping, Customs Conventions and Overrides

如果你的业务要求之一是,大多数财产不应失效,那么你就应该通过向汽车主提供自己的公约来证明这一违约。 查看

然后,如果你有需要与你的公约稍有差别的地图,那么你可以通过执行<条码>的自动数据集;T>,在你中,只具体说明了加入公约的栏目/架/军舰。

The documentation at the FluentNHibernate wiki on Overrides and Conventions is actually quite good, I highly recommend reading it.

<>Read only entities

If I was doing this, what I d do is have an NHibernate ignored, internal set property called something like IsReadonly { get; internal set; }, when an object is retrieved from somewhere that it should be read-only, then set that property before returning it to the caller.

如果在存放处有明确的<代码>Save<>/code>方法,除非有<代码>true,否则你可以检查该财产,而不是实际的NHibernate。 如果你依靠NHibernate dirty检查来节约会议Flush ,那么你可以实施NHibernate 听器,如果该财产为true,则该实体不会节省费用。

<><>Identifiers

One word (acronym) GUID; hi-lo can work, but it can get complicated and a bit finicky. For NHibernate to properly track the object it has to have a unique ID. If you re using auto ids then NHibernate will go to the database to get an ID when you Save your entity and before you do the Flush.

古阿姆集团公司解决了你与汽车和花.相关的问题,以换取在我们的银行中占用略微更多的空间和记忆。 如果贵实体拥有一个GUID作为其Id的类型,则在使用FluentNHibernate automapping时,它将自动使用

问题回答

暂无回答




相关问题
nHibernate one-to-many inserts but doesnt update

Instead of getting into code, I have a simple question. Default behavior for a simple one-to-many is that it inserts the child record then updates the foreign key column with the parent key. Has ...

How Do I copy an existing nhibernate object as a new object?

I a persisted NHibernate object that I would like to repersist as a new entity. How do I get NHibernate to save this object as if it was a new? I am thinking I might create a session interceptor to ...

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

NHibernate Search in a List using ICriteria

I have my class X : public class ClassX { public virtual IList<ClassY> ListY { get; set; } ... } My ClassX mapping (using Fluent) ... HasMany<ClassX>(x => x.ListY ) ....

热门标签