Entity Framework CodeFirst Move Data From One table To another

折月煮酒 提交于 2019-12-08 12:32:49

问题


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:

  1. Use a loop to iterate over each row in table A.
  2. While looping, add the row information from table A, along with the other data that must be copied, to table B.
  3. Verify that the data in table B contains the information you need
  4. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!