Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Fluent-NHibernate with tables in different database schemas

I have a database that I'm running several applications from. I like to separate the tables by creating a schema for each application. For my newest application I'm using FluentNHibernate. Seems like I have most of the plumbing correct but when I try to query one of my tables it can not find my table. I ran query analyzer and saw the schema was not included in the query.

I simply do not know what to put on my class (entity or mapper) so NHibernate knows which schema the class belongs to. Where and what do I place inside my classes to link them to a schema?

I've used Castle ActiveRecord in the past and it had an attribute property similar to this:

[ActiveRecord(schema=sports)]

Thanks for your help.

like image 328
Eric Neunaber Avatar asked Jul 08 '10 05:07

Eric Neunaber


People also ask

What is the difference between NHibernate and fluent NHibernate?

Fluent NHibernate offers an alternative to NHibernate's standard XML mapping files. Rather than writing XML documents, you write mappings in strongly typed C# code. This allows for easy refactoring, improved readability and more concise code.

Is NHibernate an ORM?

NHibernate is a popular, fast growing ORM with a helpful community of seasoned developers. Used in thousands of commercial and open source projects.

What is NHibernate mapping?

nhibernate Mappings Xml Mappings It is a syntax xml file which contains the metadata required for the object/relational mapping. The metadata includes declaration of persistent classes and the mapping of properties (to columns and foreign key relationships to other entities) to database tables.


1 Answers

After reading more, the answer can be found on the Fluent NHibernate's FAQ portion of the website.

http://wiki.fluentnhibernate.org/Mapping_a_collection_that_uses_a_private_backing_field

public class PersonMap : ClassMap<Person>
{
  public PersonMap()
  {
    Schema("alternativeSchema");
  }
}
like image 104
Eric Neunaber Avatar answered Oct 12 '22 14:10

Eric Neunaber