1
votes

I'm new to NHibernate, So I'm not sure if I this is even the place to ask questions. But here goes.

This is my problem:

I am building a website using Orchard CMS. All the Orchard tables are mapped by NHibernate. I also have tables in the same database that are NOT mapped by NHibernate. These tables were provided by the client. I need to query these tables and display data on the front end using Orchard. I must keep the table schemas in tact. I have a tutorial on how to map tables using NHibernate, however everything I see in the tutorials, requires the tables to have an ID column as the Primary key. None of the tables provided to me by the client have ID as the first/Primary key column. Is it possible to map to these tables without using the ID method? Or a variation of the ID method?

Id(x => x.Id);

Instead can I map to the table using:

MyColumnName/Primarykey(x => x.Id);

or

Id(x => x.MyColumnname/PrimaryKey);

Again, at this point I cannot migrate the data into new tables mapped by NHibernate and also the table schema must remain in tact. As the Client is updating these tables on a nightly bases.

Any help is appreciated.

Thanks

1
Do the tables have any primary key? - Chris Chilvers
Yes they do have Primary keys. They are just not an ID column. For example the Primary key and first column in one of the tables is: TopicCode(First column/Primary key. Will this work? Id(x => x.TopicCode); Map(x => x.BrochureDesc); Map(x => x.URL); Map(x => x.ControlPrice); Map(x => x.City); Map(x => x.Country); - EB.
Are you using Fluent Nhibernate or Loquacious mappings to map your tables? - TedOnTheNet
I am using FluentNHibernate.Mapping; - EB.
Shoot. Chris your comment disappeared. Can you repost? - EB.

1 Answers

2
votes

you can specify different columnnames for properties and even different types if y

table Topic
(
  TopicCode int,
  BrochureDesc text,
  URL text,
  ...
  primary key(TopicCode)
)

public TopicMap()
{
    Id(x => x.Id, "TopicCode").GeneratedBy.Native();
    Map(x => x.BrochureDescription, "BrochureDesc");
    Map(x => x.URL);
    ...
}

Edit:

public TopicMap()
{
    CompositeId()
        .KeyProperty(x => x.Subtitle)
        .KeyProperty(x => x.Description)
        .KeyProperty(x => x.ImageURL);
}