错误插入数据库SQL Server 2008中 [英] error insert in database sql server 2008

查看:76
本文介绍了错误插入数据库SQL Server 2008中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

控制台应用程序

_____________________
实体框架

______________________

在运行时我收到此消息

无法更新实体集"T_Cars",因为它具有DefiningQuery并且没有< insertfunction>元素存在于< modificationfunctionmapping>中.支持当前操作的元素


______________________________________________
表名称和字段

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

SELECT TOP 1000 [CarID]
      ,[Brand]
      ,[Model]
  FROM [EntityFW].[dbo].[T_Cars]
___

___________________________________________
在文件app.config
__________________________

___________________________________________
in file app.config
__________________________

<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>


______________________________________________


______________________________________________

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();
        }
}
}



添加了代码块[/编辑]



Code block added[/Edit]

推荐答案

//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();
        }
}
}


这篇关于错误插入数据库SQL Server 2008中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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