I have many-to-may relationship between two tables that breaks by introducing another table in between, containing primary keys of both.
and here is my model classes
Navigation_Functions
public class Navigation_Functions
{
public Navigation_Functions()
{
}
[Key]
public int Function_ID { get; set; }
[StringLength(250)]
[Required(ErrorMessage = "Required Title")]
[Display(Name = "Function Title")]
public string FunctionName { get; set; }
[Required(ErrorMessage = "Required Hierarchy Level")]
[Display(Name = "Hierarchy Level")]
public int Hierarchy_Level { get; set; }
public ICollection<Navigation_FunctionHierarchy> Navigation_FunctionHierarchy { get; set; }
public ICollection<Navigation_FunctionInAction> Navigation_FunctionInAction { get; set; }
public ICollection<Navigation_FunctionInController> Navigation_FunctionInController { get; set; }
}
Navigation_FunctionController Model
public class Navigation_FunctionController
{
public Navigation_FunctionController()
{
}
[Key]
public int ControllerID { get; set; }
[StringLength(250)]
[Required]
public string ControllerName { get; set; }
public ICollection<Navigation_FunctionAction> Navigation_FunctionAction { get; set; }
public ICollection<Navigation_FunctionInController> Navigation_FunctionInController { get; set; }
}
Navigation_FunctionInController Model
public Navigation_FunctionInController()
{
}
[Key]
public int FunctionInController_ID { get; set; }
public int Function_ID { get; set; }
public int ControllerID { get; set; }
public Navigation_FunctionController Navigation_FunctionController { get; set; }
public Navigation_Functions Navigation_Functions { get; set; }
}
I have generic repository for CRUD operation
public void InsertEntity(TEntity obj)
{
_DbSet.Add(obj);
}
Now I have class responsible to insert data by calling generic repository and pass object with data, I am struggling to insert data as how I insert primary of both tables into Navigation_FunctionInController table, where Functions and Controller record are creating at same time. ??????????????????????????????????????
I am reading blogs Insert/Update Many to Many Entity Framework . How do I do it? but I am struggling to understand how to insert data with my structure.
?????????
public void CreateFunctionNavigation(FunctionsNavigation_ViewModel _obj)
{
using(var _uow = new FunctionsNavigation_UnitOfWork())
{
try
{
??????????????????????
}
catch
{
}
}
}
My ViewModel
public class FunctionsNavigation_ViewModel
{
public Navigation_Functions _Navigation_Functions { get; set; }
public Navigation_FunctionController _Navigation_FunctionController { get; set; }
}
I have updated my model as been suggested but still failing to save data in database, following is screen shot from debug code.