Click here to Skip to main content
15,896,493 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
console application

_____________________
entity framework

______________________

in runtime i receive this message

Unable to update the EntitySet 'T_Cars' because it has a DefiningQuery and no <insertfunction> element exists in the <modificationfunctionmapping> element to support the current operation


______________________________________________
table name and fields
SQL
SELECT TOP 1000 [CarID]
      ,[Brand]
      ,[Model]
  FROM [EntityFW].[dbo].[T_Cars]
___
___________________________________________
in file app.config
__________________________

HTML
<configuration>
  <connectionstrings>

    <add name="DBEntityFW_Entities" connectionstring="metadata=res://*/BusinessObject.csdl|res://*/BusinessObject.ssdl|res://*/BusinessObject.msl;provider=System.Data.SqlClient;provider connection string="Data Source=YAZDAN3-PC;Initial Catalog=EntityFW;User ID=Login_Boss;Password=123;MultipleActiveResultSets=True"" providername="System.Data.EntityClient" />

  </connectionstrings>
</configuration>

______________________________________________
C#
namespace EntityFrameWorkExample
{
    class Program
    {
        static void Main(string[] args)
        {
           Insert();

        }

        static void Insert()
        {
        //# ___________________________________ insert 
            DBEntityFW_Entities DBase = new DBEntityFW_Entities();

            T_Cars objT_Cars_Add = new T_Cars();
            objT_Cars_Add.Brand = "Ford";
            objT_Cars_Add.Model = "195"; 

            DBase.T_Cars.AddObject(objT_Cars_Add);
            DBase.SaveChanges();
            Console.WriteLine("car add to the database"); 

            Console.ReadLine();
        }
}
}


[Edit]Code block added[/Edit]
Posted
Updated 27-Oct-12 0:17am
v2

1 solution

//you missed to write one line in your code ,
//your code must be like this


namespace EntityFrameWorkExample
{
    class Program
    {
        static void Main(string[] args)
        {
           Insert();
 
        }
 
        static void Insert()
        {
        //# ___________________________________ insert 
            DBEntityFW_Entities DBase = new DBEntityFW_Entities();
 
            T_Cars objT_Cars_Add = new T_Cars();
            objT_Cars_Add.Brand = "Ford";
            objT_Cars_Add.Model = "195"; 
 
            DBase.T_Cars.AddObject(objT_Cars_Add);
            DBase.T_Cars.InsertOnSubmit();
            DBase.SaveChanges();
            Console.WriteLine("car add to the database"); 
 
            Console.ReadLine();
        }
}
}
 
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