代表IList实体框架 4.0 中的属性
我们定义了一个模型类,我想从 EF 4.0 edmx 生成该模型类以实现持久性。该类大致如下:
[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; }
}
如何在 edmx 设计界面上表示路由和路径?除了使用单个 Guid Id 字段创建两个实体然后设置 1-* 与 Schedule 的关联之外,我看不到其他任何方法。我宁愿不必这样做,因为我们将拥有一个 Route 和 Path 类,但这不是我们目前想要的。
我们还没有机会了解 Code First,也没有时间为这个项目弄清楚它,但它能支持我们的需求吗?
感谢您的任何帮助。
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 Paths 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须使用相关实体,或者不能直接映射它们。例如,您可以映射另一个名为
RoutesSerialized
和PathsSerialized
的字段,它们的类型为字符串,包含所有存储为字符串并用分号分隔的 Guid。您当前的属性将使用 returnIEnumerable
并使用内部使用的函数,例如String.Join
、String.Split
、ToString
和Guid.Parse。You must either use related entities or you musn't map them directly. You can for example map another fields called
RoutesSerialized
andPathsSerialized
which will be of type string and contains all Guids stored as strings and separated by semicolon. Your current properties will use returnIEnumerable
and use internally use functions likeString.Join
,String.Split
,ToString
andGuid.Parse
.