I'm trying to build a int[] array from returned values from the database,
Normally for an int[] array that isn't database driven you would do something like this:
int[] arr1 = new int[] { 3, 4, 5 };
my public variable is as follows:
public int[] SelectedItems { get; set; } // Which is used for the multi select list box
I then when retrieving the values do something like this:
model.SelectedItems = (from x in collection select x.Id).ToArray();
but I get the error:
Cannot convert source type 'dynamic[]' to target type 'int[]'
I have googled this error but with no avail.
My collection looks like this:
public class UserActivities
{
public int Id { get; set; }
public string ActivityDesc { get; set; }
}
Update
I'm using dapper.net to retrieve the values so once I've made the call to the DB I then read it as follows:
var activities = sqlCon.Read().ToList();
I use this in two places, first place I display the string description which is shown on the page for the user, the Id's I try to reference and build an array which is used else where in the application.
collectionvariable infrom x in collectionis declared?collectionto your question. It would seem that it is not anIQueryable<UserActivities>.connection.Query<UserActivities>(" your sql statement here", new [] { your query parameters here });?