0

The SQL Data has the following Content:
string Username = admin
string Password = admin
string Email = admin@admin.com
boolean Active = 1 string Permissions = 1;4;7;8;9

The issue here is, that it won't fill my List "Permissions".
In the Database as you see above I have just 1 Field with Semicolon separated values.
All these various values need to be put into the List named Permissions.

The error message I get is the following:
Message = "LINQ to Entities does not recognize the method 'System.String[] Split(Char[])' method, and this method cannot be translated into a store expression."

public class UserData
    {
        public string Username { get; set; }
        public string Password { get; set; }
        public string Email { get; set; }
        public bool active { get; set; }
        public List<string> Permissions { get; set; }
    }

var Results = from a in context.UserAdmin
                      select new UserData
                      {
                          Username = a.Username,
                          Password = a.Password,
                          Email = a.Email,
                          Active = a.Active,
                          Permissions= a.Permissions.Split(';').ToList()                              
                      };

I have seen some thread in the internet talking about this, but the solutions did not really fit for me. And I don't want to create an additional query or something like that. I would like to solve this with one or two lines inside this LINQ query if possible.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
Maik
  • 1,582
  • 3
  • 12
  • 13
  • 1
    The right solution is to not store delimited values in a column. Use the relational database for what it is for. – crthompson Mar 19 '15 at 22:05
  • Additionally, you could store the delimited string and create your list of `UserData`, then loop the list and split the string outside entity framework. – crthompson Mar 19 '15 at 22:07
  • There is no supported translation for the method `Split` just like the error says. You will need to query the database and then perform your `Split` after. See [this answer](http://stackoverflow.com/a/10080047/182821) for an example of that. – Chris Mar 19 '15 at 22:08
  • OK got it. Thanks to all of you for the quick an efficient responses. – Maik Mar 19 '15 at 22:11

0 Answers0