문제

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;
}
도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top