我創建了一個簡單的Windows控制檯應用程序來使用VS2012和.NET 4.5測試實體框架。如何使用EF刪除實例?
我添加了一個ADO.NET實體數據模型來從我的數據庫創建一個模型。我用這個語法來使用它,但我怎樣才能刪除一些東西?
static void Main(string[] args)
{
using (var ctx = new HKDBEntities())
{
int wordId=2;
var selectedWords = (from o in context.Addresses
where o.word== wordId
select o).FirstOrDefault();
//these syntaxt is unavailable why????
ctx.Words.Delete(word);
ctx.DeleteObject(word);
// i test remove method but works not gave me some error
context.Words.Remove(selectedWords);
}
}
如何使用刪除語法?
的int從CTX刪除數據的wordID = 2; var selectedWords =(從上下文中的o.Addresses where o.word == wordId select 0).FirstOrDefault();我測試這種方式,但給了我錯誤 – motevalizadeh 2013-02-14 11:36:20
@motevallizadeh:什麼錯誤? – 2013-02-14 11:37:21
錯誤\t \t 1爲最好重載方法匹配 'System.Data.Entity.DbSet卸下襬臂(ConsoleApplication2.words)' 具有一些無效參數\t G:\ XXX/Program.cs的\t ConsoleApplication2 –
motevalizadeh
2013-02-14 11:38:49