Call a stored procedure with LINQ.ExecuteQuery to return non-displayed fields

I have a stored procedure that returns all the fields of a table plus one, that is:

tablename.*,count(suchandsuch)

Of course, when doing this through LINQs ExecuteQuery, I can return the table class instances to IEnumerable <>, but I also need an extra field that stores the stored proc.

Is it possible?

My current code is as follows:

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;
}
+3
source share
1 answer

One thing you can do is change your stored procedure and put one output variable in it

eg:

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

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

, , dll desinger,

: http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/03/13/10236.aspx

+1

Source: https://habr.com/ru/post/1752437/


All Articles