实体框架代码优先原始集合 [英] Entity Framework Code First primitive collections

查看:106
本文介绍了实体框架代码优先原始集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于以下简单情况,持久存储简单基元集合的最佳/简单方法是什么?

Given the following simple scenario, what is the best/simpleset way to have a simple collection of primitives persisted?

public class Subscriber
{
    public int Id { get; set; }
    public string Email { get; set; }
    public ICollection<int> SubscribedNodeIds { get; set; }
}

如果我执行上面的示例,SubscribedNodeIds列将被忽略.

If I execute the above example the SubscribedNodeIds column is ignored.

推荐答案

显而易见的答案是要像这样建立关系:

The obvious answer is to create relationship like so:

public class Subscriber
{
    public int Id { get; set; }
    public string Email { get; set; }
    public ICollection<Subscription> Subscriptions { get; set; }
}

public class Subscription
{
    public int Id { get; set; }
    public int NodeId { get; set; }
    public Subscriber Subscriber { get; set; }
}

这篇关于实体框架代码优先原始集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆