Return Custom Object from Entity framework and assign to Object Data Source

前端 未结 3 1223
暗喜
暗喜 2021-01-18 02:02

I need some guidance with an issue, I am using Entity Framework 4.0, I have a DAL and BLL and am binding to ObjectDataSource on the page.

I had to write a stored pr

3条回答
  •  遇见更好的自我
    2021-01-18 02:52

    what about something like this:

    using (AdventureWorksEntities context = new AdventureWorksEntities())
    {
        string myQuery = @"SELECT p.ProductID, p.Name FROM 
            AdventureWorksEntities.Products as p";
    
        foreach (DbDataRecord rec in new ObjectQuery(myQuery, context))
        {
            Console.WriteLine("ID {0}; Name {1}", rec[0], rec[1]);
        }
    }
    

提交回复
热议问题