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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:35:56+00:00 2026-05-15T19:35:56+00:00

I’m trying to adopt Fluent NHibernate with my project, currently I can get data

  • 0

I’m trying to adopt Fluent NHibernate with my project, currently I can get data from database, when I’m at application server, data is include its PK but when I return this data (as List) to client all of its PK is loose.

How can I fixed this problem?

Update

My POCO class is below: PKs are CountryCd and CityCd

public class coCity
{
    public virtual string CountryCd { get; private set; }
    public virtual string CityCd { get; private set; }
    public virtual string CityNameTH { get; set; }
    public virtual string CityNameEN { get; set; }
    public virtual int DeliveryLeadTime { get; set; }
    public virtual string CreateBy { get; set; }
    public virtual DateTime CreateDate { get; set; }
    public virtual string UpdateBy { get; set; }
    public virtual DateTime UpdateDate { get; set; }

    public override bool Equals(object obj)
    {
        return this.GetHashCode().Equals(obj.GetHashCode());
    }

    public override int GetHashCode()
    {
        return (this.CountryCd + this.CityCd).GetHashCode();
    }
}

Mapping class:

public class coCityMap : ClassMap<coCity>
{
    public coCityMap()
    {
        Table("coCity"); // this is optional

        CompositeId()
            .KeyProperty(x => x.CountryCd)
            .KeyProperty(x => x.CityCd);
        Map(x => x.CityNameTH);
        Map(x => x.CityNameEN);
        Map(x => x.DeliveryLeadTime);
        Map(x => x.CreateBy);
        Map(x => x.CreateDate);
        Map(x => x.UpdateBy);
        Map(x => x.UpdateDate);
    }
}

Source code to get data at application server

public List<coCity> GetTest()
{
    List<coCity> result = new List<coCity>();

    var sessionFactory = CreateSessionFactory();

    using (var session = sessionFactory.OpenSession())
    {
        result = (List<coCity>)session.CreateCriteria(typeof(coCity)).List<coCity>();
    }

    return result;
}

When its still at application server data is retrieve correctly as image below
alt text http://img138.imageshack.us/img138/1071/serverside.png

However when this data transit back to client side all of its PKs is loose like below.
alt text http://img203.imageshack.us/img203/1664/clientside.png

  • 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-15T19:35:57+00:00Added an answer on May 15, 2026 at 7:35 pm

    First of all, this isn’t a problem with Fluent NHibernate so:

    1. Serializable must be used on your POCO’s when you serialize them.
    2. (from your comment) NHibernate keeps a reference of the object retrieved from the database to a cache (1-st level cache). While you serialize this ‘managed’ object the output of the serialization is an unmanaged object. Nhibernate does not detect that a an object exists in the db just because you set an value in a newly constructed object. You must get the object from the database and update its properties and call Update() or you work with pure sql with the object that returned from the client (yikes!).

    Note that is irrelevant with this question: your Equals() implementation is really bad as it doesn’t take into account types and depends only on GetHashCode value. If all your classes have this implementation you could run into trouble.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
I am currently running into a problem where an element is coming back from
I have a view passing on information from a database: def serve_article(request, id): served_article
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.