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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:33:42+00:00 2026-05-13T09:33:42+00:00

I have the following class: public class Product { public virtual Guid Id {

  • 0

I have the following class:

public class Product
{
  public virtual Guid Id { get; set; }
  public virtual string Name { get; set; }
  public virtual Decimal PricePerMonth { get; set; }
  public virtual BillingInterval DefaultBillingInterval { get; set; }
  public virtual string AdditionalInfo { get; set; }
}

and the mapping looks like this:

 <class name="Product" table="Products">
    <id name="Id" column="ProductId">
      <generator class="guid.comb"/>
    </id>
    <property name="Name" column="ProductName" not-null="true" type="String" />
    <property name="PricePerMonth" column="PricePerMonth" not-null="true" type="Decimal" />
    <property name="DefaultBillingInterval" type="int" not-null="true" />
    <property name="AdditionalInfo" type="string" not-null="false" />
</class>

I use a Repository<T> class with the following method (Session is a property that returns the current session):

public IEnumerable<T> FindAll(DetachedCriteria criteria)
{
  return criteria.GetExecutableCriteria(Session).List<T>();
}

Now when I do the following (the session is the same session used in the repository):

IEnumerable<ProductDTO> productDTOs = null;
using(ITransaction tx = session.BeginTransaction(IsolationLevel.ReadCommitted))
{
    var products = repository.FindAll(new DetachedCriteria.For<Product>().Add(Restrictions.Like("Name", "Some Product%")));
    productDTOs = ToDTOs(products);
    tx.Commit();
}
// Do stuff with DTO's

The commit statement is there, because I use a service layer which automatically commits every transaction if no errors occured. I just collapsed my service layer here for easier visualization..

My ToDTOs method simply converts to a DTO:

private IEnumerable<ProductDTO> ToDTO(IEnumerable<Product> products)
{
  return products.Select(x => new ProductDTO()
    {
      Id = x.Id,
      Name = x.Name,
      PricePerMonth = x.PricePerMonth,
      AdditionalInfo = x.AdditionalInfo
    }).ToList();
}

My nhibernate log shows the following output:

2010-01-04 19:13:11,140 [4] DEBUG NHibernate.SQL - SELECT ... From Products ...
2010-01-04 19:13:11,237 [4] DEBUG NHibernate.SQL - UPDATE Products ...
2010-01-04 19:13:11,548 [4] DEBUG NHibernate.SQL - UPDATE Products ...
...

So by selecting the products it issues an update statement for every product returned when the session commits, even though nothing has been changed in the products..

Any ideas?

  • 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-13T09:33:43+00:00Added an answer on May 13, 2026 at 9:33 am

    I only had this effect when I had an entity that does not return the same value from the property than the value that has been assigned to it. Then it is treated as dirty by NH.

    Example:

    class Foo
    {
      private string name;
    
      public string Name 
      { 
        // does not return null when null had been set
        get { return name ?? "No Name"; }
        set { name = value; }
      }
    
    }
    

    This is how I would write the mapping file.

    <class name="Product" table="Products">
        <id name="Id" column="ProductId">
          <generator class="guid.comb"/>
        </id>
        <property name="Name" column="ProductName" not-null="true" />
        <property name="PricePerMonth" not-null="true" />
        <property name="DefaultBillingInterval" not-null="true" />
        <property name="AdditionalInfo" />
    </class>
    

    You don’t need to specify types. They are determined by NHibernate at runtime.

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

Sidebar

Related Questions

I have the following .Net class: public class Product { public int ID {get;set;}
I have the following class public class UIControl { public string FName{ get; set;
I have the following domain class: public class Product { public virtual Guid Id
I have following entities: public class Product { [Key] public int Id{get;set;} //other properties
I have the following class public class MenuVeiculo { public string Nome { get;
I have the following class public class CountrySpecificPIIEntity { public string Country { get;
I have the following class public class CountrySpecificPIIEntity { public string Country { get;
I have the following model: public class Product { public int Id { get;
given the following class definition: public class Order { public IProduct Product {get;set;} }
I have the following class... public class Product { public int Id { 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.