2009-07-18 1 views
0

Ich verwende NHibernate 2.1CR1. Ich veränderte die nhibernate Probe von hier http://weblogs.asp.net/pwilson/archive/2005/05/26/409042.aspx mit der neuen VersionEigenschaft mit Formel (generiert = immer) generiert ungültiges SQL für die Post-Einfügung Wählen

Die Klasse

namespace Wilson.NHibernate.Example 
{ 
     public class Contact 
     { 
       private int id; // Database-Generated Key Field 
       private string name; 
       private Address address = new Address(); // Embedded Object Type 
       private IList categories = new ArrayList(); // Many-To-Many 
Relationship 
       private IList details = new ArrayList(); // One-To-Many Relationship 

     virtual public int Id 
     { 
         get { return this.id; } 
       } 

     virtual public string Name 
     { 
         get { return this.name; } 
         set { this.name = value; } 
       } 

     virtual public Address Address 
     { 
         get { return this.address; } 
       } 

     virtual public IList Categories 
     { 
         get { return this.categories; } 
       } 

     virtual public IList Details 
     { 
         get { return this.details; } 
       } 

       public override string ToString() { 
         return this.name; 
       } 

     virtual public string PropertyWithFormula 
     { 
      get; 
      set; 
     } 
     } 
} 

Hier ist das relevante Mapping-Fragment zu arbeiten

<class name="Wilson.NHibernate.Example.Contact, 
WilsonNHibernateExample" table="Contacts" discriminator-value="?" > 
       <id name="Id" column="ContactId" access="nosetter.camelcase" unsaved- 
value="0"> 
         <generator class="identity" /> 
       </id> 
       <discriminator column="ContactType" /> 
       <property name="Name" column="ContactName" /> 
       <component name="Address" class="Wilson.NHibernate.Example.Address, 
WilsonNHibernateExample" access="nosetter.camelcase"> 
         <property name="Line" column="AddressLine" not-null="false" /> 
         <property name="City" column="AddressCity" not-null="false" /> 
         <property name="State" column="AddressState" not-null="false" /> 
         <property name="Zip" column="AddressZip" not-null="false" /> 
       </component> 

    <property name="PropertyWithFormula" formula="('TestFormula')" 
generated="always" /> 

       <bag name="Categories" table="CategoryContacts" cascade="none" 
access="nosetter.camelcase" lazy="false" inverse="false"> 
         <key column="ContactId" /> 
         <many-to-many column="CategoryId" 
class="Wilson.NHibernate.Example.Category, WilsonNHibernateExample" /> 
       </bag> 
       <bag name="Details" cascade="all" access="nosetter.camelcase" 
lazy="false" inverse="true"> 
         <key column="ContactId" /> 
         <one-to-many class="Wilson.NHibernate.Example.Detail, 
WilsonNHibernateExample" /> 
       </bag> 
       <subclass name="Wilson.NHibernate.Example.Person, 
WilsonNHibernateExample" discriminator-value="P" /> 
       <subclass name="Wilson.NHibernate.Example.Business, 
WilsonNHibernateExample" discriminator-value="B"> 
         <property name="Company" column="CompanyName" /> 
       </subclass> 
     </class> 

========= ==========================================

Hier sind die Spuren von SQL Server: Als ich session.Get (1) aufrufen, wird die SQL korrekt generiert: (‚‘ TestFormula ‚‘) als formula0_0_

exec sp_executesql N'SELECT contact0_.ContactId as ContactId2_0_, 
contact0_.ContactName as ContactN3_2_0_, contact0_.AddressLine as 
AddressL4_2_0_, contact0_.AddressCity as AddressC5_2_0_, 
contact0_.AddressState as AddressS6_2_0_, contact0_.AddressZip as 
AddressZip2_0_, contact0_.CompanyName as CompanyN8_2_0_, 
(''TestFormula'') as formula0_0_, contact0_.ContactType as 
ContactT2_2_0_ FROM Contacts contact0_ WHERE 
[email protected]',N'@p0 int',@p0=1 

Aber wenn ich einen Einsatz, der dann eine weitere Auswahl feuert die zu erhalten Generierte Werte Es generiert eine ungültige SQL für die gleiche Eigenschaft: contact_. als formula0_

exec sp_executesql N'SELECT contact_. as formula0_ FROM Contacts 
contact_ WHERE [email protected]',N'@p0 int',@p0=14 

Was mache ich falsch?

Antwort

0

Hallo dies ist eine lange gedreht, aber warum nicht erzeugt gesetzt = ‚Einfügen‘ auf diese Weise die ID auf dem begehen ... aktualisiert wird gehofft, ich nicht die gewünschte Funktionalität falsch verstanden haben

Verwandte Themen