I am trying to make a simple insert with a foreign key, but it seems to me that I need to use db.SaveChanges()for each record. How can I use only one db.SaveChanges()at the end of this program?
public static void Test()
{
using (var entities = new DBEntities())
{
var sale =
new SalesFeed
{
SaleName = "Stuff...",
};
entities.AddToSalesFeedSet(sale);
var phone =
new CustomerPhone
{
CreationDate = DateTime.UtcNow,
sales_feeds = sale
};
entities.AddToCustomerPhoneSet(phone);
entities.SaveChanges();
}
}
After running the above code, I get this exception:
System.Data.UpdateException: An error occurred while updating records. See InnerException for more details. The specified value is not an instance of a valid constant type. Parameter name: value.
EDIT: Changed the sample code and added the returned exception.
source
share