I have these two tables
public partial class Items
{
public Items()
{
this.Variables = new HashSet<Variable>();
}
public int Id { get; set; }
public string name {get; set};
//other columns
public virtual ICollection<Variable> Variables { get; set; }
}
}
And
public partial class Variable
{
public Variable()
{
this.Items= new HashSet<Items>();
}
public int Id { get; set; }
public string name {get; set};
//other stuff
public virtual ICollection<Items> Items{ get; set; }
}
}
tr These were both created automatically from a database first Entity Framework (update model from database in the edmx file). I need to be able to update the junction table that is created from
public virtual ICollection<Template> Templates { get; set; }
public virtual ICollection<Variable> Variables { get; set; }
The junction table is just two columns TemplateId and VariableID which are both the FK to the respective tables.These need to match on the name of Item and Variable. which currently i am able to accomplish somewhat with (I dont get ID from the Item Table):
foreach (var tempItem in db.Items)
{
var item = db.Variables.FirstOrDefault(x => x.Name tempItem.Name);
db.Variables.Add(item);
}
db.SaveChanges();
edit: The sql for what i am trying to accomplish is:
select Top 1000 V.ID, I.ID
FROM [PageflexWeb].[dbo].[Variables] as V, [PageflexWeb].[dbo].[Items] as I
Where V.Name = I.Name
Which works fine, but i need a way to save this to the junction table dbo.ItemVariables
Any help would be greatly appreciated.
I have read through all the documentation on msdn and stack but I am unable to find the answer that I am looking for.