Set an alias in entity without defined relation in a query using QuerySpec

Posts   
 
    
Posts: 61
Joined: 14-Feb-2017
# Posted on: 24-Jan-2020 11:48:23   

Hi,

Some of my views are reversed as entity because I want to be able to use them in Linq query. Because theses "entities" are in fact views, they haven't any foreign keyand so I can't use the

LeftJoin(XXXEntity.Relations.YYYY)

syntax but must use the following one

LeftJoin(qf.XXX).On(....)

In one of mys query, I want to use QuerySpec and add the same view (as entity) twice but can't figure how to set an alias in this case.


var query = qf.GenieCivilView
.From(qf.GenieCivilView     
.LeftJoin(qf.StationView, "ALIAS").On(StationViewFields.Id == GenieCivilViewFields.IdStation)

To summary, I want to set an alias on a entity (corresponding to a view) in a query using QuerySpec. Is there a way to do it or not ?

Thanks in advance

  • LLBLGEN : 5.6 (5.6.0) RTM - build 2019/08/20
  • Database : Oracle 11g
Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 24-Jan-2020 12:43:29   

When needed, you should use .As() to alias the entity, and .Source() to set the alias on the field.

e.g.

var q = qf.Create()
.Select(
() => new
{
    ID = OrderFields.OrderId.ToValue<int>(),
    LastName = EmployeeFields.LastName.Source("E").ToValue<string>(),
    ManagerName = EmployeeFields.LastName.As("ManagerName").Source("M").ToValue<string>()
})
.From(qf.Order
        .InnerJoin(qf.Employee.As("E")).On(OrderFields.EmployeeId == EmployeeFields.EmployeeId.Source("E"))
        .LeftJoin(qf.Employee.As("M")).On(EmployeeFields.EmployeeId.Source("M") == EmployeeFields.ReportsTo.Source("E")));

var results = adapter.FetchQuery(q);

Posts: 61
Joined: 14-Feb-2017
# Posted on: 24-Jan-2020 14:46:45   

Thanks.

As always, efficient simple_smile