It is a matter of using the right naming strategy. You can tell NHibernate to use your private field for "set" and your public property for "get". In order to to do it you must use the right access strategy.
<class name="Customer" table="customer"> <property name="customerId" column="CustomerId" type="Guid" access="field.*camelcase*" /> </class> Look for naming strategy in NHibernate documentation for more details. sds On Fri, Aug 7, 2009 at 9:02 AM, wesley <[email protected]> wrote: > > Hi all, > > I'm currently using several classes with read-only properties (with a > getter only). These properties are pre-defined or calculated values, > which shouldn't be changed by my programm. > > A example class looks as follows: > public class Customer { > private Guid customerId; > public Guid CustomerId { > get { return customerId; } > } > } > > And my mapping file looks as follows (very simplified): > <class name="Customer" table="customer"> > <property name="customerId" column="customerId" type="Guid" > access="field" /> > </class> > > Now I am working with LINQ to select my data with nHibernate. In > general the selects works fine, but I can't use any Where-clause, > because LINQ cannot resolve my public properties (Error Message "Could > not resolve property"). > var query = from c in nhSession.Linq<Customer>() > where c.CustomerId = customerId > select c; > > The exception seems correct for me, because in the mapping file I > specified my private field "customerId". LINQ on the other hand tries > to resolve my public property "CustomerId" which is not specified in > my mapping file. > > My questions is now: Is the combination of field-mapping and LINQ > possible or are these both techniques are contradictory? Do I have to > use public properties (with full access getter/setter) for my mapping > to use the benefits of LINQ? Or is there a trick to use LINQ with my > private fields? > > Thanks > -wesley > > > > -- Humberto C Marchezi --------------------------------------------------------- Master in Electrical Engineering - Automation Software Consultant and Developer at the Town Hall of Vitória --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nhusers?hl=en -~----------~----~----~----~------~----~------~--~---
