Click here to Skip to main content
15,901,426 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
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(); 


error in sd.products.Add(t);
Posted
Comments
Kornfeld Eliyahu Peter 18-Oct-15 5:36am    
What error?
Khadar Babu Salijamala 18-Oct-15 5:39am    
rError 1 The best overloaded method match for 'System.Data.Entity.DbSet<efbatchjob.product>.Add(EFBatchJob.Product)' has some invalid arguments C:\khadar\EFBatchJob\EFBatchJob\BatchJob.cs 125 29 EFBatchJob
Khadar Babu Salijamala 18-Oct-15 6:40am    
dbentityvalidationexception was unhandled this was the error message ,how can i resolve this

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...
 
Share this answer
 
Comments
Khadar Babu Salijamala 18-Oct-15 6:34am    
An unhandled exception of type 'System.Data.Entity.Validation.DbEntityValidationException' occurred in EntityFramework.dll
Quote:
System.Data.Entity.DbSet.Add(EFBatchJob.Product)

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
 
Share this answer
 
Comments
Khadar Babu Salijamala 18-Oct-15 6:34am    
An unhandled exception of type 'System.Data.Entity.Validation.DbEntityValidationException' occurred in EntityFramework.dll
C#
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();
             }
            }
          }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900