Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi Guys,

I was wondering if you could help me as I am a bit stumped at the moment.
I am trying to use the SQLDependency object(s) to write a windows service for sending e-mails upon the creation of entries in a table.

My DAL is produced using Entity Framework version 5 and is working for one object. However I have now tried to repeat the process for another object and as soon as my Notifier tries to register the query, I am getting the following error:

SQL
[Invalid, Statement, Subscribe]:
SELECT
[Extent1].[Id] AS [Id],
[Extent1].[Sid] AS [Sid],
[Extent1].[Created] AS [Created],
[Extent1].[LastUpdated] AS [LastUpdated],
[Extent1].[Completed] AS [Completed],
[Extent1].[Private] AS [Private],
[Extent1].[Status] AS [Status]
FROM [dbo].[Initiatives] AS [Extent1]
WHERE ( NOT ([Extent1].[Id] IN (22,24,25,38,39,40,41,42,43,44,45,47))) AND ( EXISTS (SELECT
        1 AS [C1]
        FROM [dbo].[InitiativeAnswers] AS [Extent2]
        WHERE [Extent1].[Id] = [Extent2].[CompletedId]
))


Now, in order to get to this stage I am using the EFChangeNotify from this Code Project Article:
SqlDependency with Entity Framework 5.0[^]

This is the C# code that is resulting in the above error:
C#
using (var initiativeCreationMonitor = 
       new EntityChangeNotifier<Initiative, Task_Entities>(
            i => !InitiativeIds.Contains(i.Id) && i.InitiativeAnswers.Any()))
{

}


I've had a look around and tried to see why this would not work and nothing seems to jump out as a cause. the query, as you can see uses the Scheme.TableName approach which is required for SQL Dependency. Now the only thing I can think of that is causing it is that I am trying to query 2 tables at the same time. Although I have not found anything to say this is not possible, it seems like the logical assumption based on the results I am getting.

Does anyone have any experience with this sort of thing, or have any ideas on how I can work around the issue? Unfortunately I am not able to change the database structure which I ideally would.
Posted
Comments
Member 13924308 24-Jul-18 17:24pm    
List my account name

1 solution

hello, if I understand correctly, the problem is in your query, because SqlDependency does not allow subqueries.
I think this link[^] can help you.
 
Share this answer
 
Comments
Pheonyx 6-Nov-13 11:30am    
Ahh, so it is because Entity Framework created a query with subqueries that it results in it failing. That's a real pain! I read that page umpteen times and missed that part. Thanks for that, I suppose I missed it because I wasn't quite sure what I was looking for!.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900