Entity Delete problem

Posts   
 
    
Posts: 3
Joined: 14-Mar-2008
# Posted on: 14-Mar-2008 13:53:25   

I have got a entity and I want delete this entity if I writes follow code , i can delete entety

entity=4; group = new GroupEntity(entityID); group.Delete(); but this code ,firts select entity and later delete I dont want this way

I writes follow code entity=4; group = new GroupEntity(); group.Fields[(int)GroupFieldIndex.Id].ForcedCurrentValueWrite(entityID); group.Delete();

but give me a error in group.Delete row: The delete action of an entity failed, probably due to the set delete restriction provided. The entity which failed is enclosed.

when group.Delete() sql profiler runs delete query exec sp_executesql N'DELETE FROM [NMS].[dbo].[Group] WHERE ( ( [NMS].[dbo].[Group].[ID] = @Id1) AND ( [NMS].[dbo].[Group].[ID] IS NULL AND [NMS].[dbo].[Group].[Name] IS NULL AND [NMS].[dbo].[Group].[DynamicGroupFilterID] IS NULL))',N'@Id1 int',@Id1=4

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 14-Mar-2008 15:42:33   

The ForcedCurrentValueWrite should work, also you may use DeleteMulti(filter) filtered on the PK value.

Similar thread: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=9689

I don't know where the"IS NULL" conditions came from. Is this entity part of an inheritance hierarchy?

hylegoz
User
Posts: 10
Joined: 11-Jul-2008
# Posted on: 14-Jul-2008 13:45:52   

Can anyone tell how can we get over of this "delete restriction" problem?

There is no restriction that I defined while generating cs codes or runtime. While I listen the SQL Server using Profiler, if I run the last SQL query manually, no problem.

Why do I get this problem?

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 14-Jul-2008 14:22:40   

Is this entity part of an inheritance hierarchy?

Please read my previous post and answer the above question.

Anyway you can use the following code to delete the entity without fetching it.

PredicateExpression filter = new PredicateExpression();
filter.Add(GroupFields.Id == 4);
GroupCollection groups = new GroupCollection();
groups.DeleteMulti(filter);