Query a <any> property

59 views
Skip to first unread message

cidico

unread,
Jun 26, 2011, 4:35:29 PM6/26/11
to nhu...@googlegroups.com
Hi,

How can I perform a query on a property that is mapped as <any> ?

For example:

<any name="Client" meta-type="string" id-type="Int32" cascade="none" lazy="false" >
      <meta-value value="Impressora" class="Printer" />
      <meta-value value="Funcionario" class="Employee" />
      <meta-value value="Cliente_externo" class="ExternalClient" />
      <meta-value value="Fornecedor" class="Supplier" />
      
      <column name="TP_CLIENTE" />
      <column name="CD_CLIENTE" />
</any>

this are my classes:

public class Client : EntityBase
{
public virtual string Name { get; set; }
public virtual string PhoneNumber { get; set; }
public virtual string Code { get; set; }
public virtual string Email { get; set; }
public virtual ClientType ClientType { get; set; }
}

public class Employee : Client
{
public Employee()
{
this.ClientType = ClientType.Employee;
}

public virtual Company Company { get; set; }
public virtual string ActiveDirectoryName { get; set; }
public virtual string Login { get; set; }
}

public class ExternalClient : Client
{
public ExternalClient()
{
this.ClientType = Enums.ClientType.ExternalClient;
}

public virtual string CityName { get; set; }
}

public class Supplier : Client
{
public Supplier()
{
this.ClientType = Enums.ClientType.Supplier;
}

public virtual string CityName { get; set; }
}

public class Printer : Client
{
public Printer()
{
this.ClientType = Enums.ClientType.Printer;
}
}


How can I can query by Employee.Name?

I'm trying to do this:

public IList<Request> ListRequests(RequestFinder finder, int pageSize, int currentPage)
{
Criticality criticalityAlias = null;
Request requestAlias = null;

Employee employeeAlias = null;
Supplier supplierAlias = null;
Printer printerAlias = null;
ExternalClient externalClientAlias = null;

var reqs = this.UnitOfWork.CurrentSession.QueryOver<Request>(() => requestAlias)
.Inner.JoinAlias(() => requestAlias.Criticality, () => criticalityAlias)
.Left.JoinAlias(() => requestAlias, () => employeeAlias);

if (finder.CriticalityId.HasValue)
{
reqs = reqs.Where(() => criticalityAlias.Id == finder.CriticalityId.Value);
}

if (!string.IsNullOrEmpty(finder.ClientName))
{
reqs.Where(() => employeeAlias.Name == finder.ClientName);
}

reqs
.OrderBy(x => x.Id)
.Desc
.Skip((currentPage - 1) * pageSize)
.Take(pageSize);

return reqs.List();
}


but I'm getting an exception that says: "any types do not have a unique referenced persister"

Is it possible?!

cidico

unread,
Jun 26, 2011, 4:37:00 PM6/26/11
to nhu...@googlegroups.com
Where you read .Left.JoinAlias(() => requestAlias, () => employeeAlias);
Please read: .Left.JoinAlias(() => requestAlias.Client, () => employeeAlias);

cidico

unread,
Jun 27, 2011, 7:13:00 PM6/27/11
to nhu...@googlegroups.com
I really would appreciate a little help here.. :)

I just wanna know if it's possible and, if possible, to know how can I perform a query on <any> property... 

Can anybody help me out here?!
Reply all
Reply to author
Forward
0 new messages