地图在实体框架代码优先方法字典 [英] Map a Dictionary in Entity Framework Code First Approach

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

问题描述

我有这样一个字典:

/// <summary>
/// Gets the leave entitlement details.
/// </summary>
/// <value>The leave entitlement details.</value>
public Dictionary<string, EmployeeLeaveEntitlement> LeaveEntitlementDetails { get; set; }  

和我想把它映射到数据库。是否有可能使用受保护的或私有列表<用于该>?如:

And I want to map it to the database. Is it possible to use a protected or private List<> for that? such as:

/// <summary>
/// Gets the leave entitlement details.
/// </summary>
/// <value>The leave entitlement details.</value>
public Dictionary<string, EmployeeLeaveEntitlement> LeaveEntitlementDetails { get; set; } 

public List<EmployeeLeaveEntitlement> LeveEntitlementStore
{
    get
    {
        List<EmployeeLeaveEntitlement> leaveEntitlements = new List<EmployeeLeaveEntitlement>();

        foreach (KeyValuePair<string, EmployeeLeaveEntitlement> leaveType in LeaveEntitlementDetails)
        {
            leaveEntitlements.Add(leaveType.Value);
        }

        return leaveEntitlements;
    }
    set
    {
        foreach (EmployeeLeaveEntitlement item in value)
        {
            this.LeaveEntitlementDetails.Add(item.LeaveType, item);
        }
    }
}



谁能帮助我?

Can anyone help me?

推荐答案

实体框架目前不支持本地映射词典。

Entity Framework does not presently support mapping a Dictionary natively.

更多信息请参见与变通如下:

See the following for more information and work-arounds:

实体框架POCO 4用字典

EF代码优先 - 地图字典或自定义类型作为一个nvarchar

http://social.msdn.microsoft .COM /论坛/ EN-US / adonetefx /线程/ a51ba903-2b8b-448E-8677-d140a0b43e89 /

这篇关于地图在实体框架代码优先方法字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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