none
Entity Framework and DB fields with null value RRS feed

  • Question

  • Hello,

     

    I just create a Web Service in C# which return an array of contact (id, last_name, first_name, phone...) which come from a MySQL DB and I get it through Entity Framework.

    When I get the xml file generate by my Web Service, I can see that the columns whose have a null value (i.e. name=null) are not write to the xml :

    record 1:

      <int_id>-1</int_id>
      <last_name>NAME-1</last_name>
      <company_id>-1</company_id>
      <addresses_id>-1</addresses_id>
      <date1 xsi:nil="true"/>
    

    record 2:

      <int_id>593</int_id>
      <last_name>NAME593</last_name>
      <company_id>501</company_id>
      <addresses_id xsi:nil="true"/>
        <position>Meister</position>
      <date1 xsi:nil="true"/>
    


    we can sse that "position" column are not insert in the first record because is value is null in the database.

    Is there a way to force Entity Framework to write it everytime else if it is null ?

     

    Very simple code of my Web Service:

      [WebMethod]
      public contact[] GetContacts()
      {
        return db.contact.ToArray();
      }
    

    many thanks in advance.

    Vincent

     

     

    Thursday, October 27, 2011 8:58 AM

Answers