[fluent-nhib] FluentMappings relationship pairing problem

2011-07-01 Thread Pleb
I had an issue today where the SchemaExport was adding an extra fk
column in a ManyToMany lookup table.

I've narrowed it down to be reproduced (sort of, the example creates
an extra table) with the following short snippet of code (inserted
below at bottom). After many hours of learning/debugging the Fluent
NHibernate internals I've found the area which is causing the unwanted
behaviour.

In the RelationshipPairingVisitor class there's a FindAlternative
method which I believe isn't taking care in finding an alternative
that also has the same child type.

When I change this line

.Where(x => x.ContainingEntityType == current.ContainingEntityType

To this

.Where(x => x.ContainingEntityType == current.ContainingEntityType &&
x.ChildType == current.ChildType)

My problem goes away.

Is it me, am I doing something wrong?

Is it a bug, should I submit a patch?

-- Thanks Pleb

class Program
{
private const string ConnectionString =
"Host=mysql1.local.test.server;User
Id=Aieg;Password=Aieg;Database=AiegTest";

static void Main()
{
using (var connection = new MySqlConnection(ConnectionString))
{
connection.Open();

using (var command = new MySqlCommand())
{
command.Connection = connection;
command.CommandText = "DROP DATABASE AiegTest;";
command.ExecuteNonQuery();
command.CommandText = "CREATE DATABASE AiegTest";
command.ExecuteNonQuery();
}
}

var sessionFactory = CreateSessionFactory();

using (var connection = new MySqlConnection(ConnectionString))
{
connection.Open();

using (var command = new MySqlCommand("SHOW TABLES;",
connection))
{
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
Console.WriteLine(reader.GetString(0));
}
}
}
}
}

private static ISessionFactory CreateSessionFactory()
{
return Fluently.Configure()

.Database(MySQLConfiguration.Standard.ConnectionString(ConnectionString))
.Mappings(m =>
m.FluentMappings.AddFromAssemblyOf())
.ExposeConfiguration(BuildSchema)
.BuildSessionFactory();
}

private static void BuildSchema(Configuration config)
{
new SchemaExport(config)
.Create(false, true);
}
}

public class ProductMap : ClassMap
{
public ProductMap()
{
Id(x => x.Id)
.GeneratedBy.GuidComb();

HasManyToMany(x => x.Retailers)
.Access.BackingField()
.Cascade.SaveUpdate()
.AsSet();

HasManyToMany(x => x.Regions)
.Access.BackingField()
.Cascade.SaveUpdate()
.AsSet();
}
}

public class RegionMap : ClassMap
{
public RegionMap()
{
Id(x => x.Id)
.GeneratedBy.GuidComb();

HasManyToMany(x => x.Products)
.Access.BackingField()
.Inverse()
.AsSet();
}
}

public class RetailerMap : ClassMap
{
public RetailerMap()
{
Id(x => x.Id)
.GeneratedBy.GuidComb();

HasManyToMany(x => x.Products)
.Access.BackingField()
.Inverse()
.AsSet();
}
}

public class Product
{
public virtual Guid Id { get; protected set; }

public virtual Iesi.Collections.Generic.ISet Retailers
{ get; private set; }

public virtual Iesi.Collections.Generic.ISet Regions
{ get; private set; }

public Product()
{
Retailers = new
Iesi.Collections.Generic.HashedSet();
Regions = new Iesi.Collections.Generic.HashedSet();
}
}

public class Retailer
{
public virtual Guid Id { get; protected set; }

public virtual Iesi.Collections.Generic.ISet Products
{ get; set; }

public Retailer()
{
Products = new Iesi.Collections.Generic.HashedSet();
}
}

public class Region
{
public virtual Guid Id { get; protected set; }

public virtual Iesi.Collections.Generic.ISet Products
{ get; set; }

public Region()
{
Products = new Iesi.Collections.Generic.HashedSet();
}
}

-- 
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To post to this group, send email to fluent-nhibernate@googlegroups.com.
To unsubscribe from this group, send email to 
fluent-nhibernate+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/fluent-nhibernate?hl=en.



[fluent-nhib] composite-element with hasmany

2011-07-01 Thread Niclas Pehrsson
Hi, I'm mapping an class with an dictionary

I want the configuration to be a composite-element which works fine,
but the configuration itself will have an dictionary.
But all I can find in the Component mapping method on AsMap is Map,
References and ParentReference.

HasMany(x =>
x.Settings).AsMap("SettingName").KeyColumn("ParentId").Component(x
=> x.HasMany())

Anyone knows what I'm doing wrong here?

-- 
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To post to this group, send email to fluent-nhibernate@googlegroups.com.
To unsubscribe from this group, send email to 
fluent-nhibernate+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/fluent-nhibernate?hl=en.



[fluent-nhib] Unique and Indexed with DataAnnotations

2011-07-01 Thread Carl B
I'm using DataAnnotations to decorate my domain objects, and have
implemented several conventions already like a ColumnLengthConvention.
But I couldn't find a good Attribute in DataAnnotations for unique or
indexed, so I just created two simple classes in my Domain

public class UniqueAttribute : Attribute { /*nothing here */ }
public class IndexedAttribute : Attribute { /*nothing here */ }

I tried to implement conventions for these attributes

public class ColumnUniqueConvention :
AttributePropertyConvention
{
protected override void Apply(UniqueAttribute attribute,
IPropertyInstance instance)
{
throw new NotImplementedException("Is this thing on?");
instance.Unique();
}
}

but my exception is never being thrown, so the automapper isn't
picking things up correctly (I have tried several string properties on
different classes and none throw the exception during ExportSchema)...
am I missing something obvious? How do I get my conventions to fire
off for these attributes?

-- 
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To post to this group, send email to fluent-nhibernate@googlegroups.com.
To unsubscribe from this group, send email to 
fluent-nhibernate+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/fluent-nhibernate?hl=en.



[fluent-nhib] Re: Add mappings by namespace

2011-07-01 Thread James Gregory
Not currently possible, but it's an open issue so we're aware of it.

-- 
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/fluent-nhibernate/-/EKk7JcsVftwJ.
To post to this group, send email to fluent-nhibernate@googlegroups.com.
To unsubscribe from this group, send email to 
fluent-nhibernate+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/fluent-nhibernate?hl=en.



[fluent-nhib] Add mappings by namespace

2011-07-01 Thread mynkow
Hi

at the moment I can add mappings like this:

cfg.FluentMappings.AddFromAssemblyOf();

The problem is that I want to filter mappings by namespace also. When I 
ILMerge my code with FluentNhibernate I got errors that some classes in 
FNhib do not have parameterless ctor.

Is that possible?


-- 
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/fluent-nhibernate/-/y4Dah9quAv0J.
To post to this group, send email to fluent-nhibernate@googlegroups.com.
To unsubscribe from this group, send email to 
fluent-nhibernate+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/fluent-nhibernate?hl=en.