【问题标题】:How to insert data from a column of an existing table into another existing table如何将现有表的列中的数据插入到另一个现有表中
【发布时间】:2015-11-14 01:00:57
【问题描述】:

我想将现有表的列中的数据插入到另一个现有表中。我正在使用实体框架在 MVC3 中执行此操作。数据通过视图从控制器添加到表中。我该怎么做?

【问题讨论】:

    标签: c# .net entity-framework model-view-controller


    【解决方案1】:
    1. 从旧表中选择您的数据。

    示例:

    using (var context = new BloggingContext()) 
    { 
    var blogs = from b in context.Blogs 
                   where b.Name.StartsWith("B") 
                   select b; 
    
    // Query for the Blog named ADO.NET Blog 
    var blog = context.Blogs 
                    .Where(b => b.Name == "ADO.NET Blog") 
                    .FirstOrDefault(); 
    }
    
    1. 将您的数据插入到新表中。

    示例:

    using (var context = new BloggingContext()) 
    { 
        var blog = new Blog { Name = "ADO.NET Blog" }; 
        context.Blogs.Add(blog); 
        context.SaveChanges(); 
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-09-01
      • 1970-01-01
      • 2010-09-25
      • 2010-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多