views:

1149

answers:

2

The function in dbml is,

    [Function(Name = "dbo.sp_GetQuestions")]
    public ISingleResult<vw_QuestionMaster> sp_GetQuestions([Parameter(Name = "Sort", DbType = "Int")] System.Nullable<int> sort, [Parameter(Name = "Title", DbType = "VarChar(50)")] string title, [Parameter(Name = "Tags", DbType = "VarChar(50)")] string tags, [Parameter(Name = "RecordFrom", DbType = "Int")] System.Nullable<int> recordFrom, [Parameter(Name = "RecordTo", DbType = "Int")] System.Nullable<int> recordTo)
    {
        IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), sort, title, tags, recordFrom, recordTo);
        return ((ISingleResult<vw_QuestionMaster>)(result.ReturnValue));
    }

The function that I defined in DataAccessLayer is,

    public static ?????????????????? GetMostDiscussedQuestions()
    {
        using (AbToBolDataClassesDataContext db = new AbToBolDataClassesDataContext())
        {
            //ISingleResult<vw_QuestionMaster> questions = db.sp_GetQuestions(1, null, null, 1, 5);
            //return questions.ToList();

            var query = from qm in db.sp_GetQuestions(1, null, null, 1, 5)
                        select qm;

            return query;
        }
    }

Here in this case, i am calling the above method to set the datasource of a gridview. Although i am getting data in query by calling the stored procedure, but please aware me about what should be the correct return type for this method. and how to fetch the same from 'query'.

I tried out with, query.ToList() but is throwing error of non-conversion of List<> type to DataTable.

+2  A: 

Unless you've specified a "Return Type" in your dbml designer, it'll be an auto-generated type, and you won't easily be able to return that from a method.

If you go into the designer, select your stored proc, and in the properties pane change the return type to be the same as your view (assuming that they both return the same structure) you should be able to keep your return type as the view that you currently are using.

Scott Ivey
A: 

solved it, :)

    public static object GetMostDiscussedQuestions()
    {
        using (AbToBolDataClassesDataContext db = new AbToBolDataClassesDataContext())
        {
            List<vw_QuestionMaster> query = db.sp_GetQuestions(1, null, null, 1, 5).ToList();

            return query;
        }
    }
Tarun Batta