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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:21:03+00:00 2026-05-26T04:21:03+00:00

i have a rather difficult mapping problem. EDIT: reformulated descritpion for historical reasons texts

  • 0

i have a rather difficult mapping problem.

EDIT: reformulated descritpion

for historical reasons texts are not stored in a column as text, instead they are saved in tables. i have several tables with following structure:

TABLE SomeEntityTexts
(
  id serial NOT NULL,
  key character varying(10),      // \
  linenumber integer,             // / unique constraint
  type smallint,
  length smallint,                // actual length of content string
  content character varying(80),
  PRIMARY KEY (id)
)

text is saved as lines with arbitrary length, different für each entity and sometimes even for different texttypes in one table.
i would like to map them to classes which handle these quirks inside and in mappings.

my solution so far:

a hidden collection and a dummy object which should be readonly. For loading there are always valid Text-objects because persisting the inner collection creates them.

internal class Textline
{
    public virtual int Id { get; set; }

    public virtual TextType Type { get; set; }   // Enum

    public virtual int Linenumber { get; set; }
    public virtual string Text { get; set; }
}

public class Textmodule
{
    public virtual int Id { get; set; }

    public virtual string Key { get; set; }      // Unique
    public virtual TextType Type { get; set; }   // Enum

    protected internal virtual IList<Textline> Textlines { get; set; }
    public virtual string Text
    {
        get { Textlines.select(t => t.Text).Aggregate(/* ...*/); }
        set { /* split text to lines with max 80 chars and feed to Textlines*/}
    }
}

public TextmoduleMap()
{
    Table("textmodules");
    ReadOnly();    // problem: shouldnt insert and update at all, but does insert
    Where("linenumber = 1");  // starts with 1

    // doesnt matter because it shouldnt be saved
    Id(text => text.Id, "id").GeneratedBy.Custom<SimpleGenerator>();

    Map(text => text.Key);
    HasMany(text => text.Textzeilen)
        .Table("textmodules")
        .PropertyRef("Key")
        .KeyColumn("key")
        .Component(c =>
        {
            c.Map(line => line.Text)
                .Columns.Add("content", "length")
                .CustomType<StringWithLengthUserType>();
            c.Map(line => line.Linenumber, "linenumber");
        })
        .Cascade.AllDeleteOrphan()
        .Not.LazyLoad();
        ;
}

My problem is, that Readonly doesnt prevent nhibernate from inserting it on save. Is there anything i can do to get it work or does someone has a better idea for a more sane domain object?

Edit2: I fiddled with SQLInsert("SELECT 1"); but i get exception “unexpected rowcount -1, expect 1”

thanks for your time

  • 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-26T04:21:04+00:00Added an answer on May 26, 2026 at 4:21 am

    i found a rather ugly way which is probably not very portable

    public TextmoduleMap()
    {
        ...
        ReadOnly();
        SqlInsert("DROP TABLE IF EXISTS temp; CREATE TEMP TABLE temp(id int); INSERT INTO temp (id) VALUES (1);");
        SqlDelete("DROP TABLE IF EXISTS temp; CREATE TEMP TABLE temp(id int); INSERT INTO temp (id) VALUES (1);");
    
        ...
    }
    

    Better ways are still welcome

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

Sidebar

Related Questions

A rather cryptic title, but it's difficult to phrase. Say I have an object
I have rather large input XML files that must be converted to a given
I have a rather large file (150 million lines of 10 chars). I need
We have a rather simple site (minimal JS) with plain html and CSS. It
I have a rather classic UI situation - two ListBoxes named SelectedItems and AvailableItems
I have a rather weak understanding of any of oracle's more advanced functionality but
We have a rather large SVN repository. Doing SVN updates are taking longer and
I have a rather big number of source files that I need parse and
I have a rather complex decorator written by someone else. What I want to
I have a rather large (many gigabytes) table of data in SQL Server that

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.