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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:06:08+00:00 2026-06-15T17:06:08+00:00

I have two classes. Class 1: public class Einsatz { public virtual ProjNrPindex Id

  • 0

I have two classes. Class 1:

public class Einsatz
{
    public virtual ProjNrPindex Id { get; set; }

    public virtual Int32? Knr { get; set; }
    public virtual String RessNr { get; set; }
    public virtual String AdrNr { get; set; }
    public virtual DateTime EndeIst { get; set; }
    public virtual DateTime StartIst { get; set; }
    public virtual DateTime ArbeitsbeginnIst { get; set; }
    public virtual String Kennwort { get; set; }

    public virtual Taetigkeit Taetigkeit { get; set; }

    public Einsatz()
    {
        this.Id = new ProjNrPindex();
    }

    public class ProjNrPindex
    {
        public virtual Int32? Pindex { get; set; }
        public virtual String ProjNr { get; set; }

        public override Boolean Equals(Object obj)
        {
            if (obj as Einsatz == null)
           {
               return(false);
           }

           if (Object.ReferenceEquals(this, obj) == true)
           {
               return(true);
           }

           ProjNrPindex other = obj as ProjNrPindex;

           if (Object.Equals(this.Pindex, other.Pindex) == false)
           {
               return(false);
           }          

           if (Object.Equals(this.ProjNr, other.ProjNr) == false)
           {
               return(false);
           }

           return(true);
       }

       public override Int32 GetHashCode()
       {
           Int32 hash = 0;

           hash += (this.Pindex != null) ? this.Pindex.GetHashCode() : 0;
           hash += 1000 * ((this.ProjNr != null) ? this.ProjNr.GetHashCode() : 0);

           return(hash);
       }
    }

    public override bool Equals(object obj)
    {
        var other = obj as Einsatz;

        if (ReferenceEquals(null, other)) return false;
        if (ReferenceEquals(this, other)) return true;

        return this.Id.Equals(other.Id);
    }

    public override int GetHashCode()
    {
        unchecked
        {
            int hash = GetType().GetHashCode();
            hash = (hash * 31) ^ this.Id.GetHashCode();

            return hash;
        }
    }
}

Class 2:

public class Taetigkeit
{
    public virtual ProjNrPindex Id { get; set; }

    public virtual string Text { get; set; }
    public virtual string RessNr { get; set; }

    public virtual Einsatz Einsatz { get; set; }

    public Taetigkeit()
    {
        this.Id = new ProjNrPindex();
    }

    public class ProjNrPindex
    {
        public virtual Int32? Pindex { get; set; }
        public virtual String ProjNr { get; set; }

        public override Boolean Equals(Object obj)
        {
            if (obj as Einsatz == null)
            {
                return (false);
            }

            if (Object.ReferenceEquals(this, obj) == true)
            {
                return (true);
            }

            ProjNrPindex other = obj as ProjNrPindex;

            if (Object.Equals(this.Pindex, other.Pindex) == false)
            {
                return (false);
            }

            if (Object.Equals(this.ProjNr, other.ProjNr) == false)
            {
                return (false);
            }

            return (true);
        }

        public override Int32 GetHashCode()
        {
            Int32 hash = 0;

            hash += (this.Pindex != null) ? this.Pindex.GetHashCode() : 0;
            hash += 1000 * ((this.ProjNr != null) ? this.ProjNr.GetHashCode() : 0);

            return (hash);
        }
    }

    public override bool Equals(object obj)
    {
        var other = obj as Einsatz;

        if (ReferenceEquals(null, other)) return false;
        if (ReferenceEquals(this, other)) return true;

        return this.Id.Equals(other.Id);
    }

    public override int GetHashCode()
    {
        unchecked
        {
            int hash = GetType().GetHashCode();
            hash = (hash * 31) ^ this.Id.GetHashCode();

            return hash;
        }
    }
}

Mappings are:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
               assembly="RestService"
               namespace="RestService">

<class name="Einsatz" table="PLANUNG">
    <composite-id name="Id">
      <key-property name="ProjNr">
        <column name="ProjNr"  />
      </key-property>
      <key-property name="Pindex">
        <column name="Pindex" />
      </key-property>


  </composite-id>


    <property name="Knr" column="Knr" />
    <property name="AdrNr" column="AdrNr" />
    <property name="RessNr" column="RessNr" />
    <property name="EndeIst" column="EndeIst" />
    <property name="StartIst" column="StartIst" />
    <property name="ArbeitsbeginnIst" column="ArbeitsbeginnIst" />
    <property name="Kennwort" column="Kennwort" />

    <one-to-one name="Taetigkeit" class="Taetigkeit" property-ref="Id"/>

</class>

</hibernate-mapping>

and

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
               assembly="RestService"
               namespace="RestService">

<class name="Taetigkeit" table="PLANBER">
    <composite-id name="Id">
        <key-property name="ProjNr">
            <column name="ProjNr"  />
        </key-property>
      <key-property name="Pindex">
            <column name="Pindex" />
        </key-property>
    </composite-id>

    <property name="RessNr" column="RessNr" />
    <property name="Text" column="Text" />

  <one-to-one name="Einsatz" class="Einsatz" property-ref="Id"/>

</class>

</hibernate-mapping>

The code:

var q = s.CreateQuery("from Einsatz e").List<Einsatz>();

gives me:

Error performing LoadByUniqueKey[SQL: SQL not available]
"The given key was not present in the dictionary."

I am afraid I am doing something horribly wrong but I don’t know what. I might add that the database in sql server has no foreign keys so the data is not quite coherent.

  • 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-15T17:06:10+00:00Added an answer on June 15, 2026 at 5:06 pm

    your equals method is flawed. it will return false when the other object it gets is not Einsatz which should be ProjNrPindex change it to the much easier implementation:

    public override bool Equals(object obj)
    {
        var other = obj as ProjNrPindex;
        return other != null &&
            Pindex == other.Pindex &&
            ProjNr == other.ProjNr;
    }
    

    Also Gethashcode will throw Overflowexception in certain situations use unchecked

    public override Int32 GetHashCode()
    {
        unchecked
        {
            return Pindex.GetOrDefault().GetHashCode() +
                1000 * ((this.ProjNr != null) ? this.ProjNr.GetHashCode() : 0);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two classes class A { public string something { get; set; }
I have two classes: class Player { public string Id { set; get; }
I have two Classes : class Customer { public string Fullname { get; set;
I have two classes: public class RichMan { public string ID {get;set;} List<Car> _cars=new
I have two classes: public class Foo { public int FooId {get;set;} public virtual
I have two classes: class Customer { public string Name { get; set; }
I have two classes: public class Reference { public virtual string Id { get;
I have two classes: public class Artikel { int id{get;set;}; string name{get;set;}; } public
I have two classes: public class Person { public int Id{get;set;} public string Name{get;set;}
I have two classes: public class DocumentViewModel { public virtual string DocumentNumber { get;

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.