I have JSON data like this one:
{
"id":"",
"firstName":"John",
"lastName":"Doe",
"phones":[
{
"value":"555-555-555",
"$$hashKey":"object:8"
},
{
"value":"444-444-444",
"$$hashKey":"object:10"
}
],
"emails":[
{
"value":"[email protected]",
"$$hashKey":"object:12"
},
{
"value":"[email protected]",
"$$hashKey":"object:18"
}
],
"tags":[
{
"value":"friend",
"$$hashKey":"object:14"
},
{
"value":"john",
"$$hashKey":"object:16"
}
],
"address":"Route 44",
"city":"NY",
"bookmarked":"",
"notes":"It's John"
}
I want to store this JSON data to database using ASP.NET MVC entity framework (Using Microsoft SQL Database). My model is auto-generated from database using ADO.NET entity framework data model. Problem that I faced is that for some reason it won't store emails/phones and tags in database. I tried everything that I could find and none of them worked for me. Does someone knows where's the problem and how can I store this JSON to my database?
EDIT 1:
After I debug contact variable in controller I notice that Email, Tags and Phones Model data are empty. I don't know how and why they are empty...
Also I add CONSTRAINT to all foreign keys
Here is database model:

this is auto-generated model from database (EF data model)
public partial class Contact
{
public Contact()
{
this.Emails1 = new HashSet<Email>();
this.Phones1 = new HashSet<Phone>();
this.Tags1 = new HashSet<Tag>();
}
public int id { get; set; }
public string firstname { get; set; }
public string lastname { get; set; }
public string address { get; set; }
public string city { get; set; }
public Nullable<byte> bookmarked { get; set; }
public string notes { get; set; }
public virtual ICollection<Email> Emails1 { get; set; }
public virtual ICollection<Phone> Phones1 { get; set; }
public virtual ICollection<Tag> Tags1 { get; set; }
}
}
and here is model For Phone/Tags/Email tables (it's same with different name in one column)
public partial class Email
{
public int id { get; set; }
public int id_contact { get; set; }
public string email1 { get; set; }
public virtual Contact Contact1 { get; set; }
}
and here is function that add data to database:
public string AddContact(Contact contact)
{
if (contact != null)
{
db.Contacts.Add(contact);
db.SaveChanges();
return "Contact Added";
}
else
{
return "Invalid Record";
}
}
HashSet<T>collections intoList<T>?