PDA

View Full Version : سوال: چگونگی درج داده sql بااستفاده از entity framework



son8989
پنج شنبه 24 مرداد 1392, 00:40 صبح
سلام دوستان : من قصددادم چندتاداده رودرون جدولم درج کنم اما موقعی که داده هامو توی تکس باکس واردمیکنم وکلیددرج روکلیک میکنم خطای
Unable to update the EntitySet 'Telephons' because it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionMapping> element to support the current operation. ---> System.Data.UpdateException: Unable to update the EntitySet 'Telephons' because it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionMapping> element to support the current operation. میده مشکلم چیه .اینم بگم وقتی اول جدولمو داخل دیتاگریدنمایش میدم درسته اما موقع عمل درج به این مشکل میخورم.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using EntityFrameWork;

namespace EntityFrameWork
{
public partial class Form1 : Form
{
ApressEntities database = new ApressEntities();
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
}

private void button1_Click(object sender, EventArgs e)
{

Telephon table = new Telephon
{
Name = textBox1.Text,
Family = textBox2.Text,
Tel = textBox3.Text,
Address = textBox4.Text,
};

database.Telephons.Add(table);
database.SaveChanges();
dataGridView1.DataSource = database.Telephons.ToList();

}
}
}

parvizwpf
پنج شنبه 24 مرداد 1392, 09:27 صبح
میشه کد کلاس apressEntity رو هم بزاری؟ اونجا تنظیمات صحیحه؟
احتمال میدم کلید اصلی یا روابط درست تعریف نشدند.

son8989
پنج شنبه 24 مرداد 1392, 11:21 صبح
میشه کد کلاس apressEntity رو هم بزاری؟ اونجا تنظیمات صحیحه؟
احتمال میدم کلید اصلی یا روابط درست تعریف نشدند.

این برنامم یه جدول بیشترنداره. یه جدول با 5 ستون که ستون ای دی کلیداولیست که توسط دیتابیس تولیدمیشه
4ستون دیگه ازنوع char هست. جدول ازطریق ado.net entity data model به برنامه add کردم.
همچین هشداریم میده
Message 1 The table/view 'Apress.dbo.Telephons' does not have a primary key defined. The key has been inferred and the definition was created as a read-only table/view. c:\users\akbar1369\documents\visual studio 2012\Projects\entity\entity\My_Model.edmx 0 1 entity

parvizwpf
جمعه 25 مرداد 1392, 10:03 صبح
ظاهرا میگه کلید اصلی برای جدولتون تعریف نکردید. این یه قانونه برای استفاده از انتیتی باید جدول شما حتما کلید اصلی داشته باشه.