Sto usando ASP.NET MVC 6 e Entity Framework 7.
Il mio modello:
public class Contact {
public int[] SelectedEstimator { set; get; }
}
Ottengo il seguente errore:
System.InvalidOperationException: The property 'SelectedEstimator'
on entity type 'ContactsManagerV3.Models.Contact'
has not been added to the model or ignored.
Se modifico la proprietà SelectedEstimator su un int, funziona. Come posso ottenere che int [] funzioni?
Stavo cercando di seguire MVC 6 - TagHelper Select
Non è possibile creare una colonna di tipo int[]
(infatti non può essere alcun tipo di matrice), che è ciò che si sta tentando di fare con la proprietà SelectedEstimator
. Puoi seguire questa risposta ( Come archiviare il doppio [] array nel database con l'approccio Entity Framework Code-First ) dove trasformano l'array in stringa per salvare l'array e quindi da stringa a array per prenderlo o puoi fare qualcosa come questo :
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; }
}
Ora puoi ottenere ciò che desideri selezionando Estimator.Value
. Spero che sia d'aiuto