开发者

Representing IList<Guid> property in Entity Framework 4.0

We have a model class defined that I want to produce from our EF 4.0 edmx for persistence. The class looks roughly as follows:

    [DataContract]
public class Schedule
{
    [DataMember]
    public string Name { get; set; }

    [DataMember]
    public Guid Id { get; set; }

    [DataMember]
    public DateTime RunDate { get; set; }

    [DataMember]
    public IList<Guid> Routes { get; set; }
    [DataMember]
    public IList<Guid> Paths { get; set; }
}

How do I represent Routes and Path开发者_JAVA技巧s on the edmx design surface? I can't see anyway of doing this other than creating two entities with a single Guid Id field then setting a 1-* Association to Schedule. I'd rather not have to do that as we'll then have a Route and Path class that isn't what we want at the moment.

We haven't had chance to look at Code First yet and don't really have time to figure it out for this project but would it support our needs?

Thanks for any assistance.


You must either use related entities or you musn't map them directly. You can for example map another fields called RoutesSerialized and PathsSerialized which will be of type string and contains all Guids stored as strings and separated by semicolon. Your current properties will use return IEnumerable and use internally use functions like String.Join, String.Split, ToString and Guid.Parse.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜