Nhibernate doing updates on select?

后端 未结 2 1514
自闭症患者
自闭症患者 2021-01-13 00:02

I have the following class:

public class Product
{
  public virtual Guid Id { get; set; }
  public virtual string Name { get; set; }
  public virtual Decimal         


        
相关标签:
2条回答
  • 2021-01-13 00:46

    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 讨论(0)
  • 2021-01-13 00:52

    Older post, but maybe this will help someone down the road.

    I have a Data Repository C# Class Library (Oracle as the database). The table value was NULL but in my repo the value was defined as Decimal and should have been ?Decimal. That fixed this update issue when running a select.

    0 讨论(0)
提交回复
热议问题