System.Data.SQLite

Login
This project makes use of Eagle, provided by Mistachkin Systems.
Eagle: Secure Software Automation
Ticket Hash: f71b4d152dd6ad2915c5b4b171a3fd191bcfa77e
Title: I can not convert an Int32 to string object
Status: Closed Type: Question
Severity: Important Priority: Medium
Subsystem: LINQ Resolution: External
Last Modified: 2017-10-16 03:02:57
Version Found In: 1.0.105.2
User Comments:
anonymous added on 2017-06-30 23:57:04:
I tried to convert to Int32 property to string property, using EF6

Public class Class1 {public string PropertyString {get; Set; }}

  Var q1 = from a in ctx.Table
            Select new Class1
            {
                PropertyString = a.PropertyInt + ""
            });

Thanks

System.NotSupportedException: Unable to cast the type 'System.Int32' to type 'System.Object'. LINQ to Entities only supports casting EDM primitive or enumeration types

Any idea or workaround?

mistachkin added on 2017-07-03 17:36:28: (text/x-fossil-plain)
Try using the ToString method on the Int32 property?  In your example:

Public class Class1 {public string PropertyString {get; Set; }}

  Var q1 = from a in ctx.Table
            Select new Class1
            {
                PropertyString = a.PropertyInt.ToString() + ""
            });

anonymous added on 2017-07-04 00:22:09: (text/x-fossil-plain)
I tried, I changed and throw error

System.NotSupportedException: LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression

mistachkin added on 2017-07-07 13:57:46: (text/x-fossil-plain)
In that case, I'm not sure how to accomplish what you are seeking.  I do not have
a lot of experience using LINQ.