mapping enum to string

mapping enum to string

Postby navirius » Wed 31 Jul 2013 04:50

I have this case with LinqConnect

1. I have enum
Code: Select all
    public enum DepositType : int
    {
   
        /// <summary>
        /// There are no comments for DepositType.Cash in the schema.
        /// </summary>
        [Description("TUNAI")]
        Cash,   
        /// <summary>
        /// There are no comments for DepositType.Credit in the schema.
        /// </summary>
        [Description("KREDIT")]
        Credit,   
        /// <summary>
        /// There are no comments for DepositType.Transfer in the schema.
        /// </summary>
        [Description("TRANSFER")]
        Transfer,   
        /// <summary>
        /// There are no comments for DepositType.TransferSaldo in the schema.
        /// </summary>
        [Description("CASH-SMS")]
        TransferSaldo
    }


2. I can use that enum with string description value, get enum value from string or convert enum to string value description attribute

3. I make private class data properties with string value that mapped by linqconnect to database
4. I make my own public properties with deposittype data type then I convert from string private properties that mapped by linqconnect, but no succes on linq query...always says can convert unmaped data

My point is I try to make string write and read from database but expose strongly type data type base on my enum to user...How I can achieve that, any hint? or trick? or workarround?

thanks for suggestion
navirius
 
Posts: 16
Joined: Sat 29 Jun 2013 11:50

Re: mapping enum to string

Postby MariiaI » Wed 31 Jul 2013 10:42

We have sent you a small test project to the e-mail address you have provided in your forum profile. Please check that the letter is not blocked by your mail filter. Please test it and notify us about the results.

If it is not what you mean, please describe the scenario you want to implement in more details, e.g.:
- the DBMS you are working with;
- the definition of an entity class and the corresponding database table you are working with;
- the full stack trace of the exception;
- some piece of code, where the exception occurs.

Also, please provide us with a simple test project or modify our sample, so that we are able to investigate this issue more closely and find the solution for you.
MariiaI
Devart Team
 
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: mapping enum to string

Postby navirius » Mon 12 Aug 2013 02:19

I looking for new version, I already implemented via extension like your example but with different approach...

thx mariial...very appreciated your help

I read changelog for new version,
"The possibility of adding custom attributes to enum members is implemented"

how can I use that feature?
navirius
 
Posts: 16
Joined: Sat 29 Jun 2013 11:50

Re: mapping enum to string

Postby MariiaI » Mon 12 Aug 2013 10:39

navirius wrote:I read changelog for new version,
"The possibility of adding custom attributes to enum members is implemented"
how can I use that feature?
Add the reference to the assembly with the attribute you need via Model > Settings > Model > Attributes. After this, add the required attribute to the model and to a particular enum property by selecting "Attributes" from its shortcut menu.
MariiaI
Devart Team
 
Posts: 1472
Joined: Mon 13 Feb 2012 08:17


Return to LinqConnect (LINQ to SQL support)