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 7940797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:28:49+00:00 2026-06-03T23:28:49+00:00

I have a database that shares columns for relationships. Here is the condensed table

  • 0

I have a database that shares columns for relationships. Here is the condensed table structure

Order
----------
OrderId int IDENTITY

OrderLine
----------
OrderId int NOT NULL
OrderLine int NOT NULL

OrderNote
----------
NoteId uniqueidentifier NOT NULL
OrderId int NOT NULL
OrderLineId int NULL

Basically the OrderNote table is shared between Order and OrderLine. If the OrderLineId column is null, the note belongs to the order. If the OrderLineId column is present, the note belongs to the order line. Here is what my classes look like:

class Order {
    int OrderId {get; set;}
    IList<OrderLine> Lines {get;}
    IList<OrderNote> Notes {get;}
}

class OrderLine {
    int OrderLineId {get; set;}
    Order Order {get; set;}
    IList<OrderNote> Notes {get;}
}

class OrderNote {
    Order Order {get; set;}
    OrderLine Line {get; set;}
    Guid NoteId {get; set;}
}

If the OrderNote.Line is null, the note belongs only to the Order. If OrderNote.Line is not null, the note belongs to the order and the line. Here is what my mappings look like:

class OrderClassMap {
    Id(x => x.OrderId).Generated.Identity();
    HasMany(x => x.Lines).Inverse().KeyColumn("OrderId");
    HasMany(x => x.Notes).Inverse().KeyColumn("OrderId");
}

class OrderLineClassMap {
    CompositeId().KeyReference(x => x.Order, "OrderId").KeyProperty(x => x.OrderLineId);
    HasMany(x => x.Notes).Inverse().KeyColumns.Add("OrderId", "OrderLineId");
}

class OrderNoteClassMap {
    Id(x => x.NoteId).Generated.Assigned();
    References(x => x.Order).Column("OrderId");
    References(x => x.Line).Columns("OrderId", "OrderLineId");
}

When I try to save a new OrderNote, I get an error saying “Invalid index 11 for this SqlParameterCollection with Count=11. How do I correctly model and map this?

  • 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-06-03T23:28:50+00:00Added an answer on June 3, 2026 at 11:28 pm

    It seems you are talking about only 1 note per order and 1 note per orderline? If so, map the note as a column in order and also a note column for the orderline. The will make a big impact on performance having less joins and simple queries – (otherwise you need left outer joins and coalesce statements).

    If you can have multiple notes per order and orderline then create seperate ordernote and orderlinenote value objects. Depends on the needs of having more that 1 note per order/orderline. Would lean towards 1 note per entity rather as this is the easiest and offers best performance and a ordernote and orderlinenote are different in terms of the domain design.

    class Order {
        int OrderId {get; set;}
        IList<OrderLine> Lines {get;}
        string Note {get;set;}
    }
    
    class OrderLine {
        int OrderLineId {get; set;}
        Order Order {get; set;}
        string Note {get;set}
    }
    

    or

    class Order {
        int OrderId {get; set;}
        IList<OrderLine> Lines {get;}
        IList<OrderNote> Notes {get;}
    }
    
    class OrderNote {
        int Id {get;set}
        Order Order {get; set;}
        string Note {get; set;}
    }
    
    class OrderLine {
        int OrderLineId {get; set;}
        Order Order {get; set;}
        IList<OrderLineNote> Notes {get;}
    }
    
    class OrderLineNote {
        int Id {get; set;}
        OrderLine OrderLine {get; set;}
        string Note {get;set}
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table within my database that has many records, some records share
I have a database that has node & nodetype tables. Nodes table NodeID ParentNodeID
I have a database table named call with columns call_time, location, emergency_type and there
I have this table in a mysql database: mysql> show columns from wifi_network_config_auth_algorithm; +------------------------+-------------+------+-----+---------+-------+
I have SQL Server 2008 database with 2 tables: Table A has columns ID
I have a SQLite database of notes that have columns _id, title, details, listid
Database is Oracle. I have a single table with three columns, A, B and
I have two Rails 3 applications that will share portions of the same database
I have a couple of jobs that use a shared resource (database), which sometimes
i have DataBase function that calculate distance by coordinates CREATE OR REPLACE FUNCTION distance(lat1

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.