Nick
Nick

Reputation: 19684

Fluent NHibernate Mapping Issue

I am trying to map several tables using Fluent Nhibernate. My tests are giving me the following error: NHibernate.Exceptions.GenericADOException: could not initialize a collection: [FluentWeb.Domain.Employees.Orders#1]

I am trying to map a one to many relationship between Employees and Orders. Orders then has a many to many relation ship with Products (NorthWind). Here are my mappings.. Can someone give me a hand. All was working with HBMs

public class EmployeeMap : ClassMap<Employees>
{

    public EmployeeMap()
    {
        Id(x => x.EmployeeID);
        Map(x => x.FirstName);
        Map(x => x.LastName);
        Map(x => x.City);
        Map(x => x.HireDate);
        Map(x => x.Title);
        HasMany(x => x.Orders)
            .AsBag().WithForeignKeyConstraintName("EmployeeID")
            .Inverse()
            .Cascade.All();


    }
}

 public class OrdersMap : ClassMap<Orders>
{
    public OrdersMap()
    {
        Id(x => x.OrderID);
        Map(x => x.OrderDate);
        Map(x => x.RequiredDate);
        Map(x => x.ShippedDate);
        References(x => x.Employee);
        HasManyToMany(x => x.Products)
            .Cascade.All()
            .WithTableName("Order Details");

    }
}

public class ProductsMap : ClassMap<Products>
{
    public ProductsMap()
    {
        Id(x => x.ProductID);
        Map(x => x.ProductName);
        Map(x => x.UnitPrice);
        HasManyToMany(x => x.Orders)
            .Cascade.All()
            .Inverse()
            .WithTableName("Order Details");


    }
}

Please let me know if more information is needed. Thanks for the help!

-Nick

Upvotes: 4

Views: 1558

Answers (1)

James Gregory
James Gregory

Reputation: 14223

Spaces in table names is usually a pretty bad idea. If you can't remove them, try surrounding the table names in backticks, which is NHibernate's database agnostic escaping mechanism.

.WithTableName("`Order Details`');

Upvotes: 2

Related Questions