views:

47

answers:

2

Hello,

i have some class which constructs itself from string, like this:

CurrencyVector v = new CurrencyVector("10 WMR / 20 WMZ");

It's actually a class which holds multiple currency values, but it does not matter much.

I need to change type of column in my LINQ table (in vs 2010 designer) from String to that class, CurrencyVector.

If i do it - i get runtime error when LINQ runtime tries to cast String as CurrencyVector (when populating the table from database). Adding IConvertible did not help.

I wrapped these columns in properties, but it's ugly and slow solution. Searching internet gave no results.

A: 

You can always extend the class and create another property that returns the object. Like so (pseudo code)

public partial class MyLinqEntity {
   public CurrencyVector  CurrencyVector {
       get {
          return new CurrencyVector(this.ColumnHoldingCurrencyVector);
       }
   }

}

where CurrencyVector has the logic to convert the string in the constructor.

Raj Kaimal
A: 

create another property

I've told that i did it! Slow and ugly solution!

UDT - i tried to use it (some time ago) - and failed. I encountered some limitations of UDT and my design was a bit wrong, so it's reasonable advise. I think i should try again with a bit reworked design, thanks!

But is there a way just to make framework call the constructor? (instead of casting from string to CurrencyVector) It could be much simpler!

And yes, i'm using linq to sql...

Alex