Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > Architecture> How to create a custom element, new user
 

Pages: 1
Architecture
How to create a custom element, new user
Page:1/1 

  Print all messages in this thread  
Poster Message
Wavel
User



Location:

Joined on:
11-Sep-2017 20:42:38
Posted:
3 posts
# 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.
  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37317 posts
# Posted on: 19-Sep-2017 22:26:31.  
the calculated field is a scalar expression, like (fieldA+fieldB) ?

Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
Wavel
User



Location:

Joined on:
11-Sep-2017 20:42:38
Posted:
3 posts
# 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
Code:
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.
  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37317 posts
# 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
Code:
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.

Quote:

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:

Code:

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
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.