Call Function on ObjectDataSource and EntityFreawork RRS feed

  • Question

  • Hi all 

    I'm new in EntityFreamwork and really will be happy if someone can help me, I have an StoredProcedure that have An select  with a function like this :

                           SELECT Flight.* , dbo.FlightRemainCapacity(FlightId) as x

                                   FRom dbo.Flight Where A=B .....

    My "FlightRemainCapacity" Sql Function Do Count() Function on table "FlightPassenger" the have a key from "Flight" table,

    Now I want To use Entityfreamwork and ObjectDataSource To do this functionality and Bind Result Filed to my GridView, How Can I Do That?

     My Function translate to Linq is Something Like = Flight.FlightPassengers.Count(item=>item.Status==1)


    • Edited by svahidm2011 Friday, September 27, 2013 4:34 PM
    Friday, September 27, 2013 4:04 PM


  • Hello,

    If I understand correctly, you want to display the query data in GridView.

    I am a bit confused that why you want to use both Entity Framework and Object Data Source.

    Because both of them are used to operate the database. We just need one of them.

    And for what you want, since you already have the procedure that will return the query result, we just need to call it and then banding the result to the GridView.

    For calling a procedure using Object Data Source, please have a look at the link below:

    The Object Data Source control calls business object methods based on the name of the method identified in the Select Method, Insert Method, Update Method, or Delete Method property, and based additionally on the parameter names that make up the business object method's signature. When you create methods in a business object, you must ensure that the parameter names and types accepted by the business object method match the parameter names and types that the Object Data Source control passes.

    If you want to use Entity Framework, please have a look at the link below:

    It will show you how to use store procedure.

    For banding the GridView using Object Data Source:

    <asp:ObjectDataSource ID="odsProducts" runat="server" SelectMethod="GetProducts"
                    TypeName="ProductsList" EnablePaging="True"  MaximumRowsParameterName="PageSize"
                    SelectCountMethod="GetRowsCount" StartRowIndexParameterName="StartRow"></asp:ObjectDataSource>
                        <asp:GridView ID="UserTable" runat="server" AllowPaging="True" DataSourceID="odsProducts"
                            SelectedIndex="0" DataKeyNames="UserID" ShowHeaderWhenEmpty="True" BorderStyle="Groove"
                            OnRowDataBound="UserTable_RowDataBound" AutoGenerateColumns="false">

    Just set DataSourceID = ObjectDataSourceID.


    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, September 30, 2013 3:48 AM