使用显示错误的实体框架将数据插入db [英] insert data to db using entity framework showing error

查看:43
本文介绍了使用显示错误的实体框架将数据插入db的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using (sampleDbEntities sd = new sampleDbEntities())
                    {
                        var t = new AccountDetails
                        {
                           Product_Name = d.Product_Name.ToString(),
                            Product_Name1 = d.Product_Name1,
                            Product_Name2 = d.Product_Name2,
                            Product_Name3 = d.Product_Name3,
                            Product_Name4 = d.Product_Name4,
                            Product_Name5 = d.Product_Name5,
                            Product_Name6 = d.Product_Name6,
                            Product_Name7 = d.Product_Name7,
                            Product_Price = d.Product_Price,
                            Product_Price1 = d.Product_Price1,
                            Product_Price4 = d.Product_Price4,
                            Product_Price2 = d.Product_Price1,
                            Product_Price3 = d.Product_Price1,
                            Product_Price5 = d.Product_Price5,
                            Product_Price6 = d.Product_Price6,
                            Product_Price7 = d.Product_Price7,
                        };

                        sd.Products.Add(t);
                        sd.SaveChanges(); 




sd.products.Add(t)中的
错误;



error in sd.products.Add(t);

推荐答案

因错误状态 System.Data.Entity.DbSet.Add(EFBatchJob.Product)期望参数类型产品,但是你传入的参数类型为 AccountDetails ...
As the error states System.Data.Entity.DbSet.Add(EFBatchJob.Product) expecting a parameter of type Product, but you pass in a parameter of type AccountDetails...


Quote:

System.Data.Entity.DbSet.Add(EFBatchJob.Product)

System.Data.Entity.DbSet.Add(EFBatchJob.Product)



需要产品类型参数,你将 AccountDetails 传递给它。

含义,方法的错误参数Add();



将类型为Product的参数传递给方法 sd.Products.Add()





-KR


It is requiring the Product type parameter and you're passing AccountDetails to it.
Meaning, wrong argument to the method Add();

Pass the argument of type Product to the method sd.Products.Add().


-KR


using (sampleDbEntities sd = new sampleDbEntities())
                   {

                       var t = new Product
                       {
                           Product_Name = d.Product_Name,
                           Product_Name1 = d.Product_Name1,
                           Product_Name2 = d.Product_Name2,
                           Product_Name3 = d.Product_Name3,
                           Product_Name4 = d.Product_Name4,
                           Product_Name5 = d.Product_Name5,
                           Product_Name6 = d.Product_Name6,
                           Product_Name7 = d.Product_Name7,
                           Product_Price = d.Product_Price,
                           Product_Price1 = d.Product_Price1,
                           Product_Price4 = d.Product_Price4,
                           Product_Price2 = d.Product_Price1,
                           Product_Price3 = d.Product_Price1,
                           Product_Price5 = d.Product_Price5,
                           Product_Price6 = d.Product_Price6,
                           Product_Price7 = d.Product_Price7

                       };
                       sd.Products.Add(t);
                       sd.SaveChanges();
             }
            }
          }


这篇关于使用显示错误的实体框架将数据插入db的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆