I have a database table:
Item{ItemId ...}
Item{BoardId ...}
ItemsInBoards{ItemId, BoardId, CreatedOnDate}
I have a models in my application
public class Item
{
public int ItemId{get;set;}
...
public virtual ICollection<Board> Boards { get; set; }
}
public class Board
{
public int BoardId{get;set;}
...
public virtual ICollection<Item> Items { get; set; }
}
Saving...
...
Item item = con.Item.Find(model.ItemId); // Find item by ID
// Try to save
Board b = con.Boards.Find(model.BoardId); // Find a board by ID
b.CreatedOnDate = DateTime.Now; // This is the issue
item.Boards.Add(b);
con.SaveChanges();
And it's saved but without CreatedOnDate
. I don't know how to set CreatedOnDAte
field to save it in database.