1

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

Community
  • 1
  • 1
Eugene Fedotov
  • 344
  • 4
  • 13
  • Have you added the contract class in the EF Databasecontext? – Rusty May 09 '16 at 17:13
  • In the example you link to, that's just a view model, not an EF POCO (at least from what I can see). SQL has no native support for arrays, so I don't see how it could be mapped to for use by EF. – Martin Costello May 09 '16 at 17:19
  • What db type do you expect it to be? – Cam Bruce May 09 '16 at 17:21
  • @MartinCostello That's what I figured. I'm a total newbie, so it's been hard to wrap my head around everything. I'm going to go learn about View Models. – Eugene Fedotov May 09 '16 at 17:25
  • @CamBruce Some sort of array, but I guess the database does not support this datatype. Then that's the problem. – Eugene Fedotov May 09 '16 at 17:27
  • @EugeneFedotov database support it ! my ans sectection there have a link . that can be help you but you must be set primary key not array – Nazmul Hasan May 09 '16 at 19:08

1 Answers1

2

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

Community
  • 1
  • 1
wajiro_91
  • 170
  • 1
  • 9