views:

23

answers:

1

I have a stored procedure which returns all the fields of a table plus one, ie:

tablename.*,count(suchandsuch)

Of course, when executing this via LINQs ExecuteQuery I can get back instances of the table's class in an IEnumerable<>, but I also want the extra field which the stored proc tacks on.

Is this possible?

My current code looks like this:

public class CategoryWithInstanceCount : DataAccess.Category
{
    [System.Data.Linq.Mapping.Column(Storage = "_Instances", DbType = "Int NOT NULL")]
    public int Instances { get; set; }
}

protected IEnumerable<CategoryWithInstanceCount> GetCategories(int? parentid)
{
    PriceDataContext context = new PriceDataContext(ConfigurationManager.ConnectionStrings["connStr"].ConnectionString);
    IEnumerable<CategoryWithInstanceCount> ie = context.ExecuteQuery<CategoryWithInstanceCount>(
        String.Format("EXEC [dbo].[GetCategoryFromParentID] @parentcategoryid = {0}", parentid == null ? "NULL" : parentid.ToString())
        );
    return ie;
}
+1  A: 

One thing you can do is modify your stored procedure and put one output variable in that

for example :

  create procedure name 
    @var1 int,
    @var2 int output,
   as
  begin

   select @var2=count (columnname), * from tablename
  end

will resolve your problem because when you drop this procedure in dbml desinger file it will create one out variable by default and will you can easily access in you code

check this for more detail : http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/03/13/10236.aspx

Pranay Rana
Interesting. Am I correct in thinking that the ExecutQuery method is not powerful enough to provide the sort of custom calling I'm trying to get? I thought there would be a substitute.
Matt W
i just want to tell you use buit in facility avaialble. when ever i wnat to exucte query which return single value or not maching with the table structure i use ExecuteQuery method of linq
Pranay Rana