在实体框架代码第一方法中映射字典 [英] Map a Dictionary in Entity Framework Code First Approach

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

问题描述

我有一本这样的字典:

/// <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);
        }
    }
}

任何人都可以帮我吗? / p>

Can anyone help me?

推荐答案

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

Entity Framework does not presently support mapping a Dictionary natively.

有关详细信息和解决方法,请参阅以下内容:

See the following for more information and work-arounds:

Entity Framework 4 POCO with Dictionary

EF Code First - Map Dictionary or custom type as an nvarchar

http:/ /social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/a51ba903-2b8b-448e-8677-d140a0b43e89/

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

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