none
Return data table RRS feed

  • Question

  • Hi,

    I am newibe in Entity Framework and WCF application. I createad an application with WCF and Entity Framework 4.0.I have a table EventTypes. It contains EventId and EventDetails. How can i return the event details to One another asp.net aplication and bind to dropdownlist with these values. How its possible?.

    Regards

    Dileep Sanker

    Sunday, April 8, 2012 5:47 PM

Answers

  • On 4/8/2012 1:47 PM, Dileep sankar wrote:
    > Hi,
    >
    > I am newibe in Entity Framework and WCF application. I createad an
    > application with WCF and Entity Framework 4.0.I have a table EventTypes.
    > It contains EventId and EventDetails. How can i return the event details
    > to One another asp.net aplication and bind to dropdownlist with these
    > values. How its possible?.
    >
     
    An EF entity is an implicit serailizable  datacontact to WCF. It means
    that you can send the EF entity to the WCF client from the WCF service
    in a collection List<Entity> (as is) and bind the List<T> to the
    control. All you have to do tell the control is what is the ID value is
    by pointing to EventId and what the string value by pointing to
    EventDetails.
     
    As in the example......
     
     
    this.DropDownList1.DataSource = myPList;
     
    this.DropDownList1.DataTextField = "Color";
     this.DropDownList1.DataValueField = "ID";
     Query for the entity and return the data as a List<T> through the WCF
    Web service.
     
    WCF contract
     
    List<EventTypes> GetEventTypes()
     
    The method that does the query and returns the queried data.
     
    public List<EventTypes> GetEventTypes()
    {
       return from a in db.Events select a;
        // You may have to do this if the above doesn't work.
        var events = new List<EventTypes>();
        var theevents = from a in db.Events select a;
        foreach(var event in theevents)
       {
          events.Add(event);
       }
        return events;
    }
     The EF entity is an object with properties, and you don't need a datatable.
     
    Also, you can change an  EF's properties on the client-side and send the
    entity/object back to the WCF service-side (as is) to be persisted to
    the database using EF,
     
    You don't need a datatable. You are using EF that has an object on the
    model, and you can return an EF/object or a collection of EF/ojects
    through WCF.
     
    Tuesday, April 10, 2012 3:47 AM

All replies

  • Hi Dileep sankar,

    Welcome to MSDN Forum.

    Please refer to the steps below.

    1. Create a contract of your WCF Service.

    2. Create a service which used to query the records from "EventTypes" table and return them.

    3. Host your service.

    4. In the Client, invoke the service and retrieve the return result.

    5. Bind the result to your dropdownlist.

    By the way, it is more related to WCF, I hope this can help.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, April 10, 2012 2:31 AM
    Moderator
  • On 4/8/2012 1:47 PM, Dileep sankar wrote:
    > Hi,
    >
    > I am newibe in Entity Framework and WCF application. I createad an
    > application with WCF and Entity Framework 4.0.I have a table EventTypes.
    > It contains EventId and EventDetails. How can i return the event details
    > to One another asp.net aplication and bind to dropdownlist with these
    > values. How its possible?.
    >
     
    An EF entity is an implicit serailizable  datacontact to WCF. It means
    that you can send the EF entity to the WCF client from the WCF service
    in a collection List<Entity> (as is) and bind the List<T> to the
    control. All you have to do tell the control is what is the ID value is
    by pointing to EventId and what the string value by pointing to
    EventDetails.
     
    As in the example......
     
     
    this.DropDownList1.DataSource = myPList;
     
    this.DropDownList1.DataTextField = "Color";
     this.DropDownList1.DataValueField = "ID";
     Query for the entity and return the data as a List<T> through the WCF
    Web service.
     
    WCF contract
     
    List<EventTypes> GetEventTypes()
     
    The method that does the query and returns the queried data.
     
    public List<EventTypes> GetEventTypes()
    {
       return from a in db.Events select a;
        // You may have to do this if the above doesn't work.
        var events = new List<EventTypes>();
        var theevents = from a in db.Events select a;
        foreach(var event in theevents)
       {
          events.Add(event);
       }
        return events;
    }
     The EF entity is an object with properties, and you don't need a datatable.
     
    Also, you can change an  EF's properties on the client-side and send the
    entity/object back to the WCF service-side (as is) to be persisted to
    the database using EF,
     
    You don't need a datatable. You are using EF that has an object on the
    model, and you can return an EF/object or a collection of EF/ojects
    through WCF.
     
    Tuesday, April 10, 2012 3:47 AM