When I need to use the complex type in entity framework?? or in other words what is the complex type used for ?
Thanks
A complex type describes the structure of one or more complex elements. Complex types are an essential part of every message model, because they define the logical structure of the messages and elements in the model.
Context. Use complex types to define structured properties for entity types or other complex types without exposing complex types themselves as an independent OData entity.
Complex types are nested data structures composed of primitive data types. These data structures can also be composed of other complex types. Some examples of complex types include struct(row), array/list, map and union. Complex types are supported by most programming languages including Python, C++ and Java.
In EF4, it's used mostly for returned values from stored procedures that don't match exactly onto an existing entity in your model. See Julie Lerman's blog post A big step for Stored Procedures in EF4 on this topic.
If you have a stored proc that returns e.g. a CustomerID, CustomerName and the total sales for that customer for last year, and you don't have any entity that matches these three fields, you can easily create a new complex type in the entity model "on the fly" to capture those value sets returned from your stored proc.
That's probably the most useful and most common usage of complex types, as far as I can tell.
For more on EF4 complex types, see Julie Lerman's blog post: Complex Types in the EDM Designer in EF4 and a look at updating complex types in code
UPDATE: there's a new interesting blog post by the EF4 team on how to "sniff stored procedure return types" and how to use automatic complex types for those return types.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With