c# - Insert Many-to-Many entities into Entity Framework error -


i've struggled far long now. i'm trying insert records relationships database, code:

public class innehåll {     public innehåll(int antal)     {         this.antal = antal;         this.frys= new hashset<frys>();     }     public innehåll() { }     [key]     public int id { get; set; }     public int antal { get; set; }     public virtual icollection<frys> frys{ get; set; }         }  public class frys {     public frys(string ort)     {         this.ort = ort;         this.innehåll = new hashset<innehåll>();     }     public frys() { }     [key]     public int id { get; set; }     public string ort { get; set; }     public int teslse { get; set; }     public virtual icollection<innehåll> innehåll { get; set; } } 

and when run code;

innehåll i1 = new innehåll(10); boxinfo b = new boxinfo {     pris = 10,     typ = "körv" };  db.boxinfos.add(b); db.frysar.add(frys);    frys.innehåll.add(i1); db.savechanges(); 

frys declared through mvc model binding.

i error on line frys.innehåll.add(i1);

object reference not set instance of object

why , how solve it?
thanks in advance.


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -