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

  • Home
  • SEARCH
  • 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 7553675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:07:29+00:00 2026-05-30T11:07:29+00:00

I have a dictionary in my class public class AffectedVehicleInScenario : DomainObjectWithId { …

  • 0

I have a dictionary in my class

public class AffectedVehicleInScenario : DomainObjectWithId {

    ... some other properties ...

    private readonly int _id;
    private readonly IDictionary<int, int> _installationRates
        = new Dictionary<int, int>();

    ... some code ...

}

and mapped it as follows

<class name="AffectedVehicleInScenario"
     table="tblAffectedVehicleInScenario"
     lazy="false">
<id name="_id"
    column="Id"
    access="field">
  <generator class="native" />
</id>

... some other properties ...

<map name="_installationRates"
     table="tblInstallationRatesOfAffectedVehicleInScenario"
     access="field"
     lazy="false">
  <key column="AffectedVehicleInScenarioId" not-null="true"/>
  <index column="Year" type="Int32"/>
  <element column="InstallationRate"
           not-null="true" 
           type="Int32"/>
</map>

Inserting works perfect but when loading from database (SQLITE) I get an exception:

Spring.Data.NHibernate.HibernateSystemException: could not initialize a collection:
[Com.QueoMedia.CO2Simulationstool.Domain.AffectedVehicleInScenario._installationRates#1][SQL: SELECT installat0_.AffectedVehicleInScenarioId as Affected1_0_, installat0_.InstallationRate as Installa2_0_, installat0_.Year as Year0_ FROM tblInstallationRatesOfAffectedVehicleInScenario installat0_ WHERE installat0_.AffectedVehicleInScenarioId=?]
---> NHibernate.Exceptions.GenericADOException: could not initialize a collection:
[Com.QueoMedia.CO2Simulationstool.Domain.AffectedVehicleInScenario._installationRates#1][SQL: SELECT installat0_.AffectedVehicleInScenarioId as Affected1_0_, installat0_.InstallationRate as Installa2_0_, installat0_.Year as Year0_ FROM tblInstallationRatesOfAffectedVehicleInScenario installat0_ WHERE installat0_.AffectedVehicleInScenarioId=?]
---> System.InvalidCastException: Die angegebene Umwandlung ist ungültig.

Could someone help me out please? Is the mapping incorrect or is it a bug in nhibernate?

Thanks in advance

Tobi

Update:
The Created table is the following:

CREATE TABLE tblInstallationRatesOfAffectedVehicleInScenario
(
    AffectedVehicleInScenarioId INT not null,
    InstallationRate SMALLINT not null,
    Year INT not null,
    primary key (AffectedVehicleInScenarioId, Year),
    constraint FKDF60481555A07D7C foreign key (AffectedVehicleInScenarioId) references tblAffectedVehicleInScenario
)
  • 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-30T11:07:30+00:00Added an answer on May 30, 2026 at 11:07 am

    i guess it is because sqlite driver returns a short boxed as object which is not directly convertable to int. you could use IDictionary<int, short> or use implement IUserType or there maybe some config to tell NH the difference.

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

Sidebar

Related Questions

I have a generic class: Public Class MyClass(Of K,V) Private _Dictionary As Dictionary(Of K,V)
I have a class that inherits a generic dictionary and an inteface public class
I have a singleton object and have a dictionary defined in it. public class
I have the following class: public class foo { public Dictionary<string, string> data =
ItemsByGuid definition: private Dictionary<string, Channel> ItemsByGuid = new Dictionary<string, Channel>(); i have a class:
I have a dictionary like the follow: public Dictionary<int, SpawnList> spawnEntities = new Dictionary<int,
I have a Word model for a dictionary/thesaurus: public class Word { public virtual
I have a class that contains a property-value (property bag) dictionary beside normal properties.
I have a dictionary of the type: IDictionary<foo, IEnumerable<bar>> my_dictionary bar class looks like
I have the following classes: public class BagA : Dictionary<string, BagB> {} public class

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.