none
How do I create a complextype with a list of items?

    Question

  • Hi,

    how do I create a complextype with a list of items (e.g. strings, or other complex type)?

    Thanks,
    Tobias

    Monday, December 21, 2009 9:26 AM

Answers

  • Hello Tobias,

    There is no support for properties that are collections of scalars or complex types in Entity Framework. The closer thing to that would be a collection navigation property that points to a collectoin of other entities. Typical cases are one-to-many (i.e. customer.Orders) or many-to-many (i.e. employee.Territories) relationships. Once you model things like that it is possible to obtain an enumeration of scalar values using a projection query, i.e.:

    var query =
        from customer in context.Customers
        where customer.CustomerID == customerID
        select new {Customer = customer, OrderAmounts = customer.Orders.Select(o => o.Amount)};

    Hope this helps,
    Diego
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Thursday, December 24, 2009 6:31 AM
    Moderator

All replies

  • Hello Tobias,

    There is no support for properties that are collections of scalars or complex types in Entity Framework. The closer thing to that would be a collection navigation property that points to a collectoin of other entities. Typical cases are one-to-many (i.e. customer.Orders) or many-to-many (i.e. employee.Territories) relationships. Once you model things like that it is possible to obtain an enumeration of scalar values using a projection query, i.e.:

    var query =
        from customer in context.Customers
        where customer.CustomerID == customerID
        select new {Customer = customer, OrderAmounts = customer.Orders.Select(o => o.Amount)};

    Hope this helps,
    Diego
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Thursday, December 24, 2009 6:31 AM
    Moderator
  • Hi Diego,

    thanks again for your answer.

    But basically I would expect the projection aka mapping to be the integral part of an Object Relational Mapper framework. For me this means, that I cannot map any data from my table to *my* complex object. Instead I can only map tables to entity types which in fact are a mere object representation of my tables. If I now need to use my own custom mapping to/from the entity types to/from *my* object it raises the question why I use entity framework at all.

    In other words: What is the value of the Entity Framework if it is not the mapping to *my* data object?

    Thanks,
    Tobias

    Monday, January 4, 2010 1:26 PM