Prashant,
I have a couple of things to note here. First, if you expect your custom stored proc to return a User entity, you will need to not alias the column names. I believe that this will cause the template logic to return a dataset/idatareader instead of an entity (I could be wrong, though). Second, from a SQL standpoint if I was going to write a stored proc like this I would use a correlated sub-query using NOT EXISTS instead of NOT IN of a LEFT JOIN simply for performance reasons. If you dataset is small, the performance gains will be negligible, but as the number of records increases the performance gains can be enormous (especially for not exists vs. not in). I would write the query like so:
SELECT
dbo.[User].user_id,
dbo.[User].role_id,
dbo.[User].first_name,
dbo.[User].last_name,
dbo.[User].email
FROM
dbo.[User] u
WHERE NOT EXISTS
(
SELECT *
FROM dbo.[ProjectMember] pm
WHERE pm.user_id = u.user_id
AND pm.project_id = @ProjectId
)
You should run the query both ways and see which is more performant (take a look at the execution plan). Also, if the table in the sub-query contains null values you can get some unexpected results using NOT IN.
Bobby - I see that you added AppendNotInQuery to the ParameterBuilder class. We may want to think about adding AppendNotExistsQuery and AppendExistsQuery. The only gotcha is making sure we can specify how to link the inner and outer queries.
Ben Johnson------------------------------
Member of the .NetTiers team
Visit
http://www.nettiers.com------------------------------