How do you output the column in the upper case in a LINQ to SQL query?

I want a UCASE or ToUpper column in my LINQ query.

var query = from rsn in db.RSLReasons
            orderby rsn.REFCMNT
            select new {rsn.REFCODE, rsn.REFCMNT};
dtReasons = query.ToADOTable(rec => new object[] { query });

If I try to run the following code:

var query = from rsn in db.RSLReasons
            orderby rsn.REFCMNT
            select new {rsn.REFCODE, rsn.REFCMNT.ToString()};
dtReasons = query.ToADOTable(rec => new object[] { query });

I get the following compilation error message:

Invalid element of anonymous type descriptor. Members of an anonymous type must be declared a member of the appointment, a simple name, or member access.

+3
source share
1 answer

Use ToUpper()... but you will need to specify the name of the property in an anonymous type, because it can no longer be output.

var query = from rsn in db.RSLReasons
            orderby rsn.REFCMNT
            select new {rsn.REFCODE, REFCMNT = rsn.REFCMNT.ToUpper()};

dtReasons = query.ToADOTable(rec => new object[] { query });
+12
source

Source: https://habr.com/ru/post/1717668/


All Articles