locked
'xxx' property on 'yyy could not be set to a 'String' value. You must set this property to a non-null value of type 'Int32'. RRS feed

  • Question

  • Hi,

    I am facing this problem due to unknown reason and I have tried every forum and blog for solving this but could not get any satisfactory answer for this.

    Let me describe the scenario.

    I have a view in database which is consisting columns from two tables. None of the tables have any column with data type "int" hence the resultant view (let's name is "MyRecord") also does not have any column with "int" data types. All the columns in the view have varchar as datatype.

    Now, in my .edmx I am adding this view and the model is created (with name "MyRecord") fine with all the properties are created fine with datatype "String". I am using Silverlight with RIA services, to after builing the application related proxies are also created fine without any confiction.

    The problem starts when I try to query the "MyRecord" using my domain context, I am getting following error.

    Load operation failed for query 'GetMyRecords'. The 'CenterCode' property on 'MyRecord' could not be set to a 'String' value. You must set this property to a non-null value of type 'Int32'.

    As seen in the error, it is clearly forcing me to convert data type of "string" column "CenterCode" to the "Int32" which is totally useless and unnecessary for me. The "String" or "varchar" columns are there because they have some business importance and changing them to "Int32" or "int" might break the application in future. Its true that "CenterCode" column has numeric data only in it but there can be character data in future thats why it is created with 'varchar' datatype.

    I can not change type of my data just because EF is not supporting.

    I am failed to understand why Entity Framework is throwing this error, it is simply not converting "varchar" to "String" and unnecessarily bringing "Int32" in picture and making the life difficult. I am struggling with this issue since last 4 hours and tried every possible way to resolve it but everything is in vein.

    Please provide some information or solution on this if anyone is having it.

    EF team, you must have some answer to this question or work around for this problem.


    Chetan Ranpariya, Software Engineer.
    • Moved by Larcolais Gong Friday, August 5, 2011 8:11 AM (From:ADO.NET Entity Framework and LINQ to Entities)
    Wednesday, August 3, 2011 12:54 PM

All replies

  • On 8/3/2011 8:54 AM, ChetanR wrote:
    > I can not change type of my data just because EF is not supporting.
    >
    >
    > Please provide some information or solution on this if anyone is having it.
    >
     
    Are you doing some kind of query using anonymous objects, anonymous
    types and with a projection?
     
    Wednesday, August 3, 2011 4:42 PM
  • Hi Arnold,

    Thanks for the reply.

    I am not querying data using anonymous objects.

    I am querying data as following.

    IEnumerable<MyRecord> myRecords = null;
    Exception error = null;
    
    EntityQuery<MyRecord> myRecordsQuery = DomainContext.GetMyRecordsQuery();
    
    DomainContext.Load(myRecordsQuery , loadOp =>
    {
            if (loadOp.HasError)
            {
              error = loadOp.Error;
            }
            else
            {
              myRecords = loadOp.Entities;
            }
    }, null);
    

    Here, loadOp.HasError is always true and loadOp.Entities contains zero elements always. loadOp.Error has the message which I posted earlier.

    Load operation failed for query 'GetMyRecords'. The 'CenterCode' property on 'MyRecord' could not be set to a 'String' value. You must set this property to a non-null value of type 'Int32'.

    I hope this will clarify your dobut.

     

    Thanks and regards,

    Chetan Ranpariya


    Chetan Ranpariya, Software Engineer.
    Thursday, August 4, 2011 4:46 AM
  • Hello,

    I suggest you open a new thread into WCF RIA Service forum for further support. http://forums.silverlight.net/53.aspx/1?WCF+RIA+Services

    Thanks for your understanding.

    Best Regards,


    Larcolais Gong[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, August 5, 2011 8:11 AM