Hi friends,
I started using NHibernate for a short time and I am developing a
large project using NHibernate.
This project is a framework for generating system in WPF, Silverlight
and Windows Phone.

A requirement of this project is that the entities are dynamic, I'm
creating the mappings at runtime.

Already develop a prototype for 6 months, and everything is working,
but now I came across a problem that can not find the solution, I'll
describe it below in a little test:

Mapping:

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="teste8" namespace="teste8">
  <class name="Entity" table="City" entity-name="City">
    <id name="ID" column="id_city">
      <generator class="native" />
    </id>
    <dynamic-component name="Attributes">
      <property name="cityname" column="cityname" type="string"
length="50" not-null="true" />
      <property name="state" column="estado" state="string"
length="50" not-null="true" />
    </dynamic-component>
  </class>
  <class name="Entity" table="Car" entity-name="Car">
    <id name="ID" column="id_car">
      <generator class="native" />
    </id>
    <dynamic-component name="Attributes">
      <property name="model" column="model" type="string" length="50"
not-null="true" />
    </dynamic-component>
  </class>
</hibernate-mapping>

Entity:

public class Entity
    {
        public virtual int ID {get; set;}
        public virtual IDictionary Attributes {get; set;}
    }

In NHibernate 2.1:
There is no problem for inserts, updates or deletes of entities
But to make the search for multiple records I use the method:
    _sessao.Linq <Entity> ("Car") (Assembly: Nhibernate.Linq)
But when you try to filter for a dynamic attribute the system throw a
execption, example:
    _sessao.Linq <Entidade> ("Car.") Where (a => a.Attributes
['model'] == "A3");
After much research I could only make the filter in dynamic attributes
using HQL , example:
    _sessao.CreateQuery ("from City WHERE state = 'NY'");
But in this case I find the following problem: The NHibernate sends 2
(TWO) queries to the database:
Eg:
 select id_city, cityname, state from City WHERE state = 'PR'
 select id_car, model from Car WHERE state = 'PR'
generating an error.

Question 1:
Is there a way to work with HQL (CreateQuery method), where it only
generates a query based on entity-name (Car or City)?

Taking advantage of the email:
In NHibernate 3.0 _sessao.Linq method was replaced by _sessao.Query,
the method
Linq had two signatures, one with no parameters _sessao.Linq <T> ()
and another signature accept the
parameter entity name _sessao.Linq <T> ("Car"), thus defining a
mapping which I am seeking the data. In NH Query 3.0 the method only
has the signature without parameters (_sessao.Query <T> ()), not
allowing for searches by entity-name.

Question 2:
Anyone know a way around this limitation of the method Query?

Sorry for the size of the email, and my poor english.
I thank everyone's attention,

Rodrigo Nunes

-- 
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.

Reply via email to