views:

107

answers:

1

Hi,,,

When I need to use the complex type in entity framework?? or in other words what is the complex type used for ?

Thanks

+2  A: 

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.

marc_s
What do you mean by "on the fly"? Could you provide some example please? Thanks
emzero
@emzero: Check out this blog post on EF4 stored procedure and how to use complex types for catching return values: http://thedatafarm.com/blog/data-access/a-big-step-for-stored-procedures-in-ef4/
marc_s