问题
I'm using Entity Framework(4.3) Code First Method For My Asp.Net Mvc3 Application.I want to do:Data of table A must be copied (along with some other data) to table B after that when Click Save Button Tabla A Data will be Removed how to implement this?
回答1:
Here are the logical steps to take. Add the following to the Save button's click event:
- Use a loop to iterate over each row in table A.
- While looping, add the row information from table A, along with the other data that must be copied, to table B.
- Verify that the data in table B contains the information you need
- Use a loop to iterate over each row in table A again, but this time remove each row.
Hope this helps.
回答2:
Maybe you should check out Entity Framework Migrations, it is very comprehensive tool for manipulations with database schema. http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-code-based-migrations-walkthrough.aspx
回答3:
May be this Solution Help for SomeOne stuck on this Problem @Tarzan helped me to complete this
IList<OrderTemp> data = _DBService.GetAllOrderTemp();//List
foreach (var result in data)
{
Order order = new Order()
{
OrderId = result.Id,
CustomerId = result.CustomerId,
SchoolNameId = result.SchoolNameId,
Supplier = result.Supplier,
StatusId = result.StatusId,
ProductCode = result.ProductCode,
ProductDescription = result.ProductDescription,
Color = result.Color,
Size = result.Size
};
_DBService.InsertOrder(order);
_DBService.DeleteOrderTemp(result);
}
来源:https://stackoverflow.com/questions/12603280/entity-framework-codefirst-move-data-from-one-table-to-another