Patch for auto map - detect <set>, recognize many to many

11 views
Skip to first unread message

Ayende Rahien

unread,
Dec 11, 2008, 1:14:52 AM12/11/08
to fluent-n...@googlegroups.com
This patch contains two new features regarding auto map.
1) it automatically detect if we should use <set> or <bag>
2) it now recognize <many-to-many> associations.
fluent_nh.patch

James Gregory

unread,
Dec 11, 2008, 5:08:57 AM12/11/08
to fluent-n...@googlegroups.com
Hey Ayende, thanks for this. I'll get it applied asap.

James Gregory

unread,
Dec 11, 2008, 5:17:53 AM12/11/08
to fluent-n...@googlegroups.com
Patch applied. Thanks for your contribution!

Chris

unread,
Dec 11, 2008, 5:27:00 AM12/11/08
to Fluent NHibernate
How does this patch work, for example, with the code given below I
get 4 tables, A, B, AToB & BToA when I'd only expect the one xToy
Table, if I take the IList<A> out of class B ithen lose both xToy
tables and get an FK on the B table (as expected). What am I doing
wrong here?


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentNHibernate.AutoMap;
using Entities;
using NHibernate.Tool.hbm2ddl;
using NHibernate.Cfg;
using FluentNHibernate.Cfg;
using NHibernate;
using System.Collections;
using Iesi.Collections.Generic;

namespace AutoMappingTest
{
class Program
{
static void Main(string[] args)
{
Configuration cfg = new Configuration();

var config = MsSqlConfiguration.MsSql2005
.ShowSql()
.ConnectionString.Is("Data Source=.;Initial
Catalog=Testing;Integrated Security=True")
.ConfigureProperties(cfg);

var model = new AutoPersistenceModel
{
Conventions =
{
GetForeignKeyNameOfParent = type => type.Name +
"Id",
GetForeignKeyName = info => info.Name + "Id",
GetManyToManyTableName = ((child,parent)
=>child.Name + "To" + parent.Name)
}
};

model
.AddEntityAssembly(typeof(A).Assembly)
.Where(entity => entity.Namespace == "Entities")
.Configure(config);

SchemaExport exporter = new SchemaExport(config);
exporter.Execute(true, true, false, true);
}
}
}

namespace Entities
{
public class A
{
public virtual Guid Id { get; set; }
public virtual string Name { get; set; }
public virtual IList<B> Bees { get; set; }
}

public class B
{
public virtual Guid Id { get; set; }
public virtual string Name { get; set; }
public virtual IList<A> Ays { get; set; }
>  fluent_nh.patch
> 19KViewDownload

Andrew Stewart

unread,
Dec 11, 2008, 5:55:07 AM12/11/08
to fluent-n...@googlegroups.com
I was just thinking the same thing, I havent looked at the code yet, but I'm guessing that there's been a convention added to the convention class.

Andy
--
=================
I-nnovate Software - Bespoke Software Development, uk wirral.
http://www.i-nnovate.net

Andrew Stewart

unread,
Dec 11, 2008, 7:49:25 AM12/11/08
to fluent-n...@googlegroups.com
Hi James

Spotted it, in the one to many parts it just check if your using the Iesi.Collections. types and if so sets the type appropriately.

Cheers

Andy

Chris

unread,
Dec 11, 2008, 8:06:39 AM12/11/08
to Fluent NHibernate
Using ISet or IList seems to make no difference to the outcome for me.

On Dec 11, 12:49 pm, "Andrew Stewart" <andrew.stew...@i-nnovate.net>
wrote:
> Hi James
> Spotted it, in the one to many parts it just check if your using
> the Iesi.Collections. types and if so sets the type appropriately.
>
> Cheers
>
> Andy
>
> On Thu, Dec 11, 2008 at 10:55 AM, Andrew Stewart <
>
>
>
> andrew.stew...@i-nnovate.net> wrote:
> > I was just thinking the same thing, I havent looked at the code yet, but
> > I'm guessing that there's been a convention added to the convention class.
> > Andy
>

Ayende Rahien

unread,
Dec 11, 2008, 11:13:03 AM12/11/08
to fluent-n...@googlegroups.com
It doesn't :-(
It needs a global view of things to make sense of that.
I'll publish a new patch, in which the conventional decision is to use the master entity as the one being first in sort order.

Ayende Rahien

unread,
Dec 11, 2008, 11:11:44 AM12/11/08
to fluent-n...@googlegroups.com
It just check for ISet<T>

Ayende Rahien

unread,
Dec 11, 2008, 12:57:41 PM12/11/08
to fluent-n...@googlegroups.com
Here is a patch to fix this issue.
fluent_nh.patch

Andrew Stewart

unread,
Dec 11, 2008, 4:56:00 PM12/11/08
to fluent-n...@googlegroups.com
Hi Oren

Glad you like the AutoMapping functionality, it's still rather early but it certainly covers the basics at the moment. Thanks for your patch's they are most appreciated. I've applied your patch now.

Andy

Ayende Rahien

unread,
Dec 11, 2008, 5:05:11 PM12/11/08
to fluent-n...@googlegroups.com
You can assume that I am going to do more there

Chris

unread,
Dec 12, 2008, 5:27:22 AM12/12/08
to Fluent NHibernate
Awesome. That's all there is to say.

On Dec 11, 5:57 pm, "Ayende Rahien" <aye...@ayende.com> wrote:
> Here is a patch to fix this issue.
>
> On Thu, Dec 11, 2008 at 6:13 PM, Ayende Rahien <aye...@ayende.com> wrote:
> > It doesn't :-(It needs a global view of things to make sense of that.
> > I'll publish a new patch, in which the conventional decision is to use the
> > master entity as the one being first in sort order.
>
>  fluent_nh.patch
> 8KViewDownload

jer...@depiction.com

unread,
Dec 15, 2008, 8:25:45 PM12/15/08
to Fluent NHibernate
Hello,

Should adding a parent to a child update the many-to-many table in the
database? In my current implementation, it seems that adding a child
to the parent creates a record in the many-to-many table without a
problem, but adding a parent to a child does not persist in the
database. Maybe there's something I'm doing wrong??

My code is similar to the code above but uses MySQL instead of MSSQL;
more details are available if needed.

Thanks,

Jereme




On Dec 11, 2:05 pm, "Ayende Rahien" <aye...@ayende.com> wrote:
> You can assume that I am going to do more there
>
> On Thu, Dec 11, 2008 at 11:56 PM, Andrew Stewart <
>
> andrew.stew...@i-nnovate.net> wrote:
> > Hi Oren
>
> > Glad you like the AutoMapping functionality, it's still rather early but it
> > certainly covers the basics at the moment. Thanks for your patch's they are
> > most appreciated. I've applied your patch now.
> > Andy
>
> > On Thu, Dec 11, 2008 at 5:57 PM, Ayende Rahien <aye...@ayende.com> wrote:
>
> >> Here is a patch to fix this issue.
>
> >> On Thu, Dec 11, 2008 at 6:13 PM, Ayende Rahien <aye...@ayende.com> wrote:
>
> >>> It doesn't :-(It needs a global view of things to make sense of that.
> >>> I'll publish a new patch, in which the conventional decision is to use
> >>> the master entity as the one being first in sort order.
>

Ayende Rahien

unread,
Dec 15, 2008, 8:45:40 PM12/15/08
to fluent-n...@googlegroups.com
That is by design, the idea here is that only one side of the association is responsible for the associatio
Reply all
Reply to author
Forward
0 new messages