A Couple Quick Questions

Posts   
 
    
Eibwen
User
Posts: 3
Joined: 11-Mar-2011
# Posted on: 11-Mar-2011 22:31:19   

I'm trying to figure out the concepts and what LLBLGen is able to do, and how to do those things.

If anyone could answer these questions, or even better point me to a resource that would explain it functionally (an in-depth tutorial)

  1. Where would you use "Value Types" vs "Typed Lists"?

  2. The ORM that i'm currently using, but is a huge pain to deal with, has the feature to be able to create "Formula Fields" which are not stored in the database, and can do things like: "TotalCostFormulaField = ServiceCost + SUM(ProductCost)" So when I grab a DataRow from it there is a TotalCostFormulaField field there that with the value, but there is no TotalCostFormulaField in the database. How would one accomplish something like this when LLBLGen is generating the O/R layer? Is there a way to have fields like i described, or would I make an object in my code that has all the fields from the framework and make my own calculated fields there?

(2 is really my main question, 1 is to show the type of information i'd love to find a resource for, the "Building Block Definitions" page is not working too well for me)

Thanks for any help you can offer.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 13-Mar-2011 14:44:33   

Eibwen wrote:

I'm trying to figure out the concepts and what LLBLGen is able to do, and how to do those things.

If anyone could answer these questions, or even better point me to a resource that would explain it functionally (an in-depth tutorial)

  1. Where would you use "Value Types" vs "Typed Lists"?

Value types and typedlists are different things. Typed lists can be seen as queries over one or more entities, and you define the resultset in the designer, so you get a typed object to fill in code. Valuetypes are groups of fields which can be seen as a single type. Valuetypes aren't supported in LLBLGen Pro runtime framework and linq to sql (so only when you select Entity framework or nhibernate as your target framework)

  1. The ORM that i'm currently using, but is a huge pain to deal with, has the feature to be able to create "Formula Fields" which are not stored in the database, and can do things like: "TotalCostFormulaField = ServiceCost + SUM(ProductCost)" So when I grab a DataRow from it there is a TotalCostFormulaField field there that with the value, but there is no TotalCostFormulaField in the database. How would one accomplish something like this when LLBLGen is generating the O/R layer? Is there a way to have fields like i described, or would I make an object in my code that has all the fields from the framework and make my own calculated fields there?

(2 is really my main question, 1 is to show the type of information i'd love to find a resource for, the "Building Block Definitions" page is not working too well for me)

Thanks for any help you can offer.

Formula fields, do you need them in code, or also in queries (so filter on the results of the formula fields) ? In code: add a property to the entity in a partial class of the entity and simply calculate the value there in the get clause of the property.

Frans Bouma | Lead developer LLBLGen Pro
Eibwen
User
Posts: 3
Joined: 11-Mar-2011
# Posted on: 14-Mar-2011 19:45:18   

Otis wrote:

Value types and typedlists are different things. Typed lists can be seen as queries over one or more entities, and you define the resultset in the designer, so you get a typed object to fill in code. Valuetypes are groups of fields which can be seen as a single type. Valuetypes aren't supported in LLBLGen Pro runtime framework and linq to sql (so only when you select Entity framework or nhibernate as your target framework)

Just to make sure I'm clear: If I load a collection of Entities, it would have all the fields (columns) in them. Then to traverse any foreign keys would that result in another select? Typed Lists can be used to only load a subset of the fields. And it would automatically load the subtables defined in it. Valuetypes kind of group fields together into an object to help normalize the data

Formula fields, do you need them in code, or also in queries (so filter on the results of the formula fields) ? In code: add a property to the entity in a partial class of the entity and simply calculate the value there in the get clause of the property.

I noticed that note, in the last paragraph of O/R Mapping page, about adding them in partial classes a couple hours after i asked.
That would be all i need i think, but is there a way to do it in queries as well? Since you bring it up simple_smile

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 15-Mar-2011 06:27:08   

Eibwen wrote:

Otis wrote:

Value types and typedlists are different things. Typed lists can be seen as queries over one or more entities, and you define the resultset in the designer, so you get a typed object to fill in code. Valuetypes are groups of fields which can be seen as a single type. Valuetypes aren't supported in LLBLGen Pro runtime framework and linq to sql (so only when you select Entity framework or nhibernate as your target framework)

Just to make sure I'm clear: If I load a collection of Entities, it would have all the fields (columns) in them. Then to traverse any foreign keys would that result in another select? Typed Lists can be used to only load a subset of the fields. And it would automatically load the subtables defined in it. Valuetypes kind of group fields together into an object to help normalize the data

If you fetch Entities/EntityCollection, you are fetching a graph. So in the CustomerEntity you will have a Orders property that is actually a EntityCollection<OrderEntity> object. Into each OrderEntity object you will have order's entity fields, and a EntityCollection<OrderDetailEntity>, into each one of these OrderDetailEntity you will have a ProductEntity. So on... If you use TypedLists, you create a flat structure (inherits from DataTable), so you wont have a graph but a plain typed DataTable. TypedLists are commonly used in reporting or just to show read-only data.

Eibwen wrote:

Formula fields, do you need them in code, or also in queries (so filter on the results of the formula fields) ? In code: add a property to the entity in a partial class of the entity and simply calculate the value there in the get clause of the property.

I noticed that note, in the last paragraph of O/R Mapping page, about adding them in partial classes a couple hours after i asked.
That would be all i need i think, but is there a way to do it in queries as well? Since you bring it up simple_smile

For calculated fields you have three options:

a. Database calculated fields. In this case, the field is read only and the database is in control of that value, so you can use that field in your predicate expressions.

b. In-memory calculated fields. This means you do calculations on the already fetched fields. For instance, you have OrderDetailEntiy with fields Price and Quantity. Now you want a field that represent the lint total, you can create a custom property in a partial class of OrderDetailEntity that calculate that:

public decimal LineTotal
{
   get
   {
      return Price * Quantity;
   }
}

c. Query-base calculated fields. This is more advance but easy to implement. is the same as "b" but the calculation is emitted in the query (not in memory). Here is how. Also here is an example for TypedLists/TypedViews.

David Elizondo | LLBLGen Support Team
Eibwen
User
Posts: 3
Joined: 11-Mar-2011
# Posted on: 15-Mar-2011 18:53:00   

Thank you very much, that cleared up everything i was asking.