2 columns -> one object

Posts   
 
    
twisty7867
User
Posts: 6
Joined: 08-Feb-2007
# Posted on: 08-Feb-2007 01:56:49   

I'm new to LLBLGen so forgive me if I ask a stupid question.

If I have a SQL 2000 table that includes these two fields:

Amount DECIMAL(18,2) CurrencyCode CHAR(3)

Is there a straightforward way to get LLBLGen to create the resultant Invoice object with a single property called Amount of a custom type called Money I have created? The money type takes string, decimal parameters in its constructor.

The point of this type is that it has an overriden ToString() method which knows the approrpriate culture for each currency code. So, for instance, if the currency code is JPY it calls decimal.ToString("c",CultureInfo.CreateSpecificCulture("ja-JP")) and the output is ¥1000 vs. if it's EUR then it will call CultureInfo.CreateSpecificCulture("fr-FR") and the output would be €1 000,00.

The point of this in general is that I could bind collections including my custom Money type to a GridView without having to write any extra code to properly format each number (each row might be in a different currency...)

If there is another better way to go about it I am certainly open to that as well simple_smile

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 08-Feb-2007 03:26:42   

If you are using .NET 2.0 you can create a partial class for your entity with the decimal and currency values. Then if your money type exists in a separate library you can add this to the generated LLBLGen project. Here's a quick example.


using System;
using System.Collections.Generic;
using System.Text;
using MyLibrary; // Contains the Money type.

namespace MyNamespace.DALAdapter.EntityClasses
{
    public partial class OrderEntity
    {
        public Money Total
        {
            get { new Money(Amount, CurrencyCode) };
        }
    }
}
twisty7867
User
Posts: 6
Joined: 08-Feb-2007
# Posted on: 08-Feb-2007 16:32:05   

This seems like a reasonable solution for the single entity objects, but is there a way to accomplish the same thing with an EntityCollection object generated by LLBLGen and it's associated DataTable?

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 09-Feb-2007 01:38:42   

Are you using self servicing or adapter?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 09-Feb-2007 12:20:54   

You implement it in the entity, so a collection of these entities all have this property set, or do you want to add the property to the collection ?

Frans Bouma | Lead developer LLBLGen Pro