On 'yyy,' the xx' attribute could not be assigned to a 'String' value. This property must be set to a non-null value of type 'Int32'.



I have attempted to find a solution on every forum and blog but have not been successful. I am experiencing this issue for an unexplained cause.

Let me explain the situation.

I have a database view made up of columns from two tables. Since there are no columns of the data type "int" in any of the tables, the resulting view (let's call it "MyRecord") similarly lacks such columns. The datatype for each column in the view is varchar.

As I add this view to my.edmx file, the model (with the name "MyRecord") is successfully generated, and all of its attributes are of the datatype "String." Because I use Silverlight with RIA services, any application-related proxies that are generated after application building go smoothly and without any issues.

When I attempt to query "MyRecord" using my domain context, I see the following error.

The load operation for the query "GetMyRecords" failed. MyRecord's 'CenterCode' attribute was unable to be changed to a 'String' value. This property must be set to a value of type "Int32" that is not null.

The issue makes it plain that I am being forced to change the data type of the "string" column CenterCode to "Int32," which is completely pointless and needless for me. Because the "String" or "varchar" columns are important to the company, converting them to "Int32" or "int" might cause the program to malfunction in the future. Although the "CenterCode" column now only contains numeric data, it may eventually include character data, which is why the "varchar" datatype was used when creating it.

Because EF does not permit changing the type of my data, I am unable to do so.

I utilized sql server profiler, and the query was correctly performed. I was also able to run the same query in SSMS without encountering any problems. Only when EF is creating objects from the data supplied by the query does the problem appear in the application.

I am unable to comprehend why Entity Framework is generating this problem; it is only failing to convert "varchar" to "String" and needlessly introducing "Int32" and complicating matters. I've been trying to fix this problem for the last four hours and have exhausted all options, but to no avail.

If there is a problem, kindly provide a remedy or information.

The EF team must have a response to this query or a solution to this issue.

8/4/2011 5:24:00 AM

Popular Answer

I had a same issue with adouble datatype.


Change your method or viewpoint and cast the column as follows:cast(columnname as int32)

1/6/2012 12:08:00 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow