Last post Sep 17, 2014 11:12 AM by joeller
Sep 16, 2014 03:30 PM|joeller|LINK
I am using EF 5.0. I am populating Framework from Database using Database First. I have two stored procedures, one which returns a particular object based on a particular id. The other which returns all of those objects which share the same foreign key
value. They return the same query structure except one returns a list and the other returns a single object. In the EF model, the complex objects describing the result of these two SPs look exactly the same one is called subline_get_result as a subLine_get_all_result
the other is called subline_get_result.
I have a model for my view that normally is populating a table so that it uses for each individual row in the table subLine_get_all_result. Rather than create a brand new model just for this one partial view, I thought I could just cast the subline_get_result
as a subLine_get_all_result. However, I got a compile time error saying I couldn't do that.
Is there some way to cast one time of complex object as another?
Sep 17, 2014 02:20 AM|Mikesdotnetting|LINK
You can't simply cast one complex object to another just because they have the same properties. As far as .NET is concerned, they are completely different types. If you want to convert one complex type to another, you need to write code that does that. You
can use conversion operators or you can use something like AutoMapper to map property values from an instance of one type to an instance of another type.
Sep 17, 2014 11:12 AM|joeller|LINK
Zeus darn it. I was hoping. In the meantime I instantiated a new of the one object and copied the values of the properties form the other object to that object, which works fine, but which I look at as being a workaround.