Delete Not Working?

Posts   
 
    
joshrivers
User
Posts: 10
Joined: 30-Dec-2008
# Posted on: 22-Jan-2009 00:56:14   

Any idea why this would not result in rows being deleted?

            var locks = from i in metadata.DatabaseState
                        where i.Parameter == ManifestProcessingLockController.LockParameterString
                        select i;
            foreach (var lockEntity in locks)
            {
                lockEntity.Delete();
            }
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 22-Jan-2009 06:32:27   

Hi Josh,

I assume you are using SelfServicing. What LLBLGen version and runtime library version?, in other words, additional infosimple_smile

I would do this: 1. Be sure to update to the latest runtime library version. 2. Double check the linq query actually returns results (>0) 3. Enable tracing to see whether there's SQL generated.

David Elizondo | LLBLGen Support Team
joshrivers
User
Posts: 10
Joined: 30-Dec-2008
# Posted on: 26-Jan-2009 01:26:13   

Sorry about that. 2.6 Final is the version I'm using. And I am indeed using self-servicing.

My Trace Result:

Method Enter: CreatePagingSelectDQ
Method Enter: CreateSelectDQ
Method Enter: CreateSelectDQ
Generated Sql query: 
    Query: SELECT DISTINCT TOP 1 COUNT(*) AS [LPAV_] FROM [ManifestServices].[dbo].[DatabaseState] [LPLA_1]  WHERE ( ( ( [LPLA_1].[Parameter] = @Parameter1)))
    Parameter: @Parameter1 : AnsiString. Length: 50. Precision: 0. Scale: 0. Direction: Input. Value: "Lock".

Method Exit: CreateSelectDQ
Method Exit: CreatePagingSelectDQ: no paging.
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_64\System.Transactions\2.0.0.0__b77a5c561934e089\System.Transactions.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_64\System.EnterpriseServices\2.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
: Initial expression to process:
value(SD.LLBLGen.Pro.LinqSupportClasses.DataSource`1[CLS.DataAccess.EntityClasses.DatabaseStateEntity]).Where(i => (i.Parameter = "Lock"))
Method Enter: DaoBase.PerformGetMultiAction
Method Enter: CreatePagingSelectDQ
Method Enter: CreateSelectDQ
Method Enter: CreateSelectDQ
Generated Sql query: 
    Query: SELECT [LPLA_1].[Parameter], [LPLA_1].[DateStamp], [LPLA_1].[Value] FROM [ManifestServices].[dbo].[DatabaseState] [LPLA_1]  WHERE ( ( ( [LPLA_1].[Parameter] = @Parameter1)))
    Parameter: @Parameter1 : AnsiString. Length: 50. Precision: 0. Scale: 0. Direction: Input. Value: "Lock".

Method Exit: CreateSelectDQ
Method Exit: CreatePagingSelectDQ: no paging.
Method Enter: DaoBase.ExecuteMultiRowRetrievalQuery
Method Exit: DaoBase.ExecuteMultiRowRetrievalQuery
Method Exit: DaoBase.PerformGetMultiAction

It doesn't like the delete ever gets processed, although it doesn't throw an exception and the loop continues.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 26-Jan-2009 07:08:56   

joshrivers wrote:

Sorry about that. 2.6 Final is the version I'm using. And I am indeed using self-servicing.

Please make SURE you're using the latest build of LLBLGen Pro and the runtime libraries (LLBLGen site -> Customer's area -> v2.6 -> RuntimeLibraries -> download, etc.)

Also, I don't know what you are getting a "SELECT DISTINCT TOP 1" in your query disappointed . What is the COUNT of the fetcht's result?

If the problem persist, please make a repro-solution so we can reproduce it further simple_smile

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 26-Jan-2009 09:43:48   

Also please place a breakpoint on the Delete() method call to see if it really gets executed.

Frans Bouma | Lead developer LLBLGen Pro
joshrivers
User
Posts: 10
Joined: 30-Dec-2008
# Posted on: 29-Jan-2009 00:47:57   

I've created and attached a repro-project.

  • I updated to the latest runtimes, and the problem persisted.
  • The distinct query seems to come from the .Count() that I put in my repro-code.
  • I also made sure the Delete method was getting called and not throwing an exception.

Thanks! Josh

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 29-Jan-2009 08:09:28   

Hi Josh,

If I'm not mistaken, your DatabaseState table doesn't have any primary key. That is an obvious problem when you try to delete: What the framework should delete? A primary key is needed to delete individual entities as this is used to identify what entity should be deleted. As the fields are "NOT NULL" you could opt for make a "virtual" PK on LLBLGenPro Designer: you select the field of the entity (in entity properties), then you check the "Is part of primary key" checkbox.

David Elizondo | LLBLGen Support Team
joshrivers
User
Posts: 10
Joined: 30-Dec-2008
# Posted on: 12-Feb-2009 04:42:48   

I got delayed checking back on this, but this was indeed the issue. Adding a virtual key made my code work right away.

Thanks!

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 12-Feb-2009 06:23:50   

Good you get this work wink

David Elizondo | LLBLGen Support Team