I am working on creating WCF restful Services and when I try adding a record via entity framework into my database I get this exception:
Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded.
I have a trigger created at my database which works as:
GO
CREATE TRIGGER [dbo].[Trigger_groupLocation_date]
ON [dbo].[groupLocation]
INSTEAD OF INSERT
AS
BEGIN
SET NoCount ON
DECLARE @s int
DECLARE @g_id int
DECLARE @lat float
DECLARE @lon float
SELECT @s = sender FROM inserted
SELECT @g_id = g_id FROM inserted
SELECT @lat = latitude FROM inserted
SELECT @lon = longitude FROM inserted
insert into [groupLocation] (sender,g_id,latitude,longitude) values(@s,@g_id,@lat,@lon)
END
One thing to note is that I am able to add records directly into the database. I read some details regarding the exception from here, and After some research I found a similar question at stackoverflow. But while trying the solution I read that DbContext doesn't have a Refresh() method so Instead I tried:
var ctx = ((IObjectContextAdapter)db).ObjectContext;
ctx.Refresh();
But I still gets the same exception. Then I read here that only if you are using code first approach then this work around can work, I am using "EF designer from database approach". How can I get access to Refresh method in data first approach?