Map a string collection to Entity Framework or Linq to SQL

I would like to know if a 1-many database relation can be matched as an array of primitives in a class of parent objects. For example, let's say I have a database as follows:

TABLE: PERSON
    ID - int

TABLE: PERSON_EMAIL_ADDRESSES
    PERSON_ID - int
    EMAIL_ADDRESS - string

For my Person class, I would like to have the following:

public class Person 
{
    public int ID { get; set; }
    public string[] EmailAddresses { get; set; }
}

The default behavior of Linq to SQL and Entity Framework would be to give me a separate class for the PERSON_EMAIL_ADDRESSES table and a collection of this type in the Person object ... this is what I don't want.

It looks like it can be done using NHibernate as described here , but is there any way to do this using EF or Linq to SQL?

Thanks in advance, Wayne

+1
1

, NHibernate, , :

var q = from p in Context.People
        select new Person // Where this is your Person type above, not a mapped entity type
        {
            ID = p.ID, 
            EmailAddresses = from pea in p.EmailAddresses
                             select pea.EmailAddress
        };

L2S, L2E. -, .

+1

All Articles