How to create a custom element, new user

Posts   
 
    
Wavel
User
Posts: 8
Joined: 11-Sep-2017
# Posted on: 19-Sep-2017 22:19:14   

Using version 5.3 targeting ef core 2.0 and have a question about how to design an element.

I need to create an element that will be the target of a query which pulls from multiple tables, and includes a few calculated columns. I tried a typed list but it does not let me add a field which will be calculated.

What is the correct method for doing what I want? Or do i create the class outside of llblgen?

Thanks.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 19-Sep-2017 22:26:31   

the calculated field is a scalar expression, like (fieldA+fieldB) ?

Frans Bouma | Lead developer LLBLGen Pro
Wavel
User
Posts: 8
Joined: 11-Sep-2017
# Posted on: 19-Sep-2017 22:49:37   

It's a string that comes back from a subquery within the query. It will either contain the string "tracking" or null.

It might be better if I give you the entire issue: I am converting from EF6 to EF Core and I have a table-valued function in sql server. It would be great if I could do

var r = db.Results.FromSql("select * from function")

where Results is a class that would have the fields returned from the function. I was not able to make that work with llblgen.

So, instead, I want to create an entity in llblgen and rewrite the sql function in linq directly.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 20-Sep-2017 15:24:26   

Wavel wrote:

It's a string that comes back from a subquery within the query. It will either contain the string "tracking" or null.

It might be better if I give you the entire issue: I am converting from EF6 to EF Core and I have a table-valued function in sql server. It would be great if I could do

var r = db.Results.FromSql("select * from function")

where Results is a class that would have the fields returned from the function. I was not able to make that work with llblgen.

EF Core doesn't support table valued functions so we can't support that in the designer.

So, instead, I want to create an entity in llblgen and rewrite the sql function in linq directly.

I think it's easier in this particular case to write the type directly as a C# class. The thing is: the designer can't map it on anything so it can't keep it in sync with the thing it is mapped on. A typed list would suffice here (which would give you a type in C#) if you wouldn't have any expression fields as well.

The generated typedlist is a linq query and a type it projects to. To extend that with field expressions isn't going to work as you can't extend the linq query (as the projection is in the query as a select).

example:


public IQueryable<CustomerOrderTypedListRow> GetCustomerOrderTypedList()
{
    var current0 = this.Customers;
    var current1 = from customer in current0
                    join order in this.Orders on customer.CustomerId equals order.Customer.CustomerId into joinresult_1
                    from order in joinresult_1.DefaultIfEmpty()
                    join orderDetails in this.OrderDetails on order.OrderId equals orderDetails.Order.OrderId
                    select new {order, customer, orderDetails };
    return current1.Select(v=>new CustomerOrderTypedListRow() { ContactName = v.customer.ContactName, CustomerId = v.customer.CustomerId, EmployeeId = v.order.Employee.EmployeeId, OrderId = v.order.OrderId, OrderDate = v.order.OrderDate, ProductId = v.orderDetails.Product.ProductId, Quantity = v.orderDetails.Quantity } );
}

This is a generated typed list. If the data you want to use in the expression is in the projected set, you can add the code in a partial class to the type it projects to, but other than that, it's a bit difficult to do I think.

Frans Bouma | Lead developer LLBLGen Pro