I'm using ASP.NET MVC 6 and Entity Framework 7.
My Model:
public class Contact {
public int[] SelectedEstimator { set; get; }
}
I get the following error:
System.InvalidOperationException: The property 'SelectedEstimator'
on entity type 'ContactsManagerV3.Models.Contact'
has not been added to the model or ignored.
If I change the SelectedEstimator property to an int, it works. How can I get int[] to work?
I was trying to follow MVC 6 - TagHelper Select
You can't create a column of int[]
type ( in fact can't be any type of array), which is what you are trying to do with the SelectedEstimator
property. You can follow this answer (How to store double[] array to database with Entity Framework Code-First approach) where they transform the array to string to save the array and then from string to array to take it or you can do something like this:
public class Estimator{
public int EstimatorId {get;set;}
public int Value {get;set;}
public int ContactId {get;set;}
public Contact Contact {get;set;}
}
public class Contact {
public int ContactId {get;set;}
public ICollection<Estimator> SelectedEstimator { set; get; }
}
Now you can accomplish what you want selecting the Estimator.Value
. Hope it helps