Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6756761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:33:48+00:00 2026-05-26T13:33:48+00:00

I have a couple of POCO objects that look like this: public abstract class

  • 0

I have a couple of POCO objects that look like this:

public abstract class DataObject : IDataObject
{
    public virtual Guid ObjectID { get; set; }
    public virtual IList<ObjectProperty> Properties { get; set; }
}

public class ObjectProperty : IProperty
{
    public virtual Guid ObjectPropertyID { get; set; }
    public virtual DataObject Object { get; set; }
    public virtual string Name { get; set; }
    public virtual string Value { get; set; }
    public virtual string Type { get; set; }
    public virtual int? Scale { get; set; }
    public virtual int? Precision { get; set; }
}

I have mappings like so:

public class DataObjectMapping : ClassMap<DataObject>
{
    public DataObjectMapping()
    {
        Table("DataObjects");

        this.MapIDataObjectProperties();
        this.MapIHasProperties();
    }
}

    public ObjectPropertyMapping()
    {
        Table("ObjectProperties");
        Id(x => x.ObjectPropertyID).Column("ObjectPropertyID");
        References(x => x.Object).Index("ixObject.Name").Column("ObjectID").Not.Nullable();
        Map(x => x.Name).Index("ixObject.Name").Length(100).Not.Nullable();
        Map(x => x.Scale);
        Map(x => x.Precision);
        Map(x => x.Type);
        Map(x => x.Value);
    }
}

I am mapping the interface properties like so:

    public static void MapIHasProperties<T>(this ClassMap<T> target) where T : IHasProperties
    {
        target.HasMany(x => x.Properties);
    }

When I generate my database (MSSQL 2005) using

    public static ISessionFactory SessionFactory
    {
        get
        {
            if (_SessionFactory == null)
            {
                var config = new Configuration().Configure();
                _SessionFactory = Fluently.Configure(config)
                    .Mappings(m=>m.FluentMappings.AddFromAssemblyOf<Site>()
                        .Conventions.Add<CustomForeignKeyConvention>())
                    .ExposeConfiguration(c => { new SchemaExport(c).Create(false, true); })
                    .BuildSessionFactory();
            }
            return _SessionFactory;
        }
    }

I end up with things linking properly, but with an extra column in my ObjectProperties table, and I don’t understand why:

USE [Sandbox]
GO
/****** Object:  Table [dbo].[ObjectProperties]    Script Date: 11/01/2011 13:50:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ObjectProperties](
    [ObjectPropertyID] [uniqueidentifier] NOT NULL,
    [Name] [nvarchar](100) NOT NULL,
    [Scale] [int] NULL,
    [Precision] [int] NULL,
    [Type] [nvarchar](255) NULL,
    [Value] [nvarchar](255) NULL,
    [ObjectID] [uniqueidentifier] NOT NULL,
    [DataObject_id] [uniqueidentifier] NULL,
PRIMARY KEY CLUSTERED 
(
    [ObjectPropertyID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
ALTER TABLE [dbo].[ObjectProperties]  WITH CHECK ADD  CONSTRAINT [FKFBE776BE7C346D9] FOREIGN KEY([DataObject_id])
REFERENCES [dbo].[DataObjects] ([ObjectID])
GO
ALTER TABLE [dbo].[ObjectProperties] CHECK CONSTRAINT [FKFBE776BE7C346D9]
GO
ALTER TABLE [dbo].[ObjectProperties]  WITH CHECK ADD  CONSTRAINT [FKFBE776BF671B18E] FOREIGN KEY([ObjectID])
REFERENCES [dbo].[DataObjects] ([ObjectID])
GO
ALTER TABLE [dbo].[ObjectProperties] CHECK CONSTRAINT [FKFBE776BF671B18E]

Can someone explain to me why I have 2 columns with foreign keys being mapped to the same column in the DataObjects table, and how I can prevent that from happening?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:33:49+00:00Added an answer on May 26, 2026 at 1:33 pm

    I found the answer here: Fluent NHibernate generates extra columns Basically I needed to specify the key column in my properties collection like so:

    public DataObjectMapping()
    {
        Table("DataObjects");
        Id(x => x.ObjectID).Column("ObjectID");
        HasMany(x => x.Properties).KeyColumn("ObjectID");
    }
    

    and all was better.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have couple of statements, the pseudo code would look something like this: insert
I have couple of tags which has same name attribute. Something like this: <img
I have a simply Class that is intended to be a simple POCO -
I have couple of dozen pieces of data that I need to save and
I have couple resource DLLs that I currently load when application starts using following
I have couple of questions about AS3 variables handling by AVM/compiler/scope .1. This code
We have couple different web-apps that share the same db link. The hibernate layer
ok I have couple of .NET classes that I want to use in VBA.
I have couple of input fields with the class link. All of them should
I have couple of objects(1 custom object called appointment and event object) which i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.