2012-01-20 104 views
0

在我的系统(C#,MVC,MSSQL,实体框架)我有一个雇员类员工离职授权字典。向数据库添加数据从字典MVC实体框架

public Dictionary<string, EmployeeLeaveEntitlement> LeaveEntitlementDetails { get; internal set; } 

EmployeeLeaveEntitlement类,如下所示,

/// <summary> 
    /// Gets or sets the type of the leave. 
    /// </summary> 
    /// <value>The type of the leave.</value> 
    public string LeaveType { get; set; } 

    /// <summary> 
    /// Gets or sets the entitlement. 
    /// </summary> 
    /// <value>The entitlement.</value> 
    public double Entitlement { get; set; } 

    /// <summary> 
    /// Gets or sets the availed count. 
    /// </summary> 
    /// <value>The availed count.</value> 
    public double AvailedCount { get; set; } 

我需要的是一个数据库连接到系统中,由于员工
我已经创建的上下文,

public DbSet<Employee> Employees { get; set; }  

当我运行该系统将创建数据库,但没有表或列的权利..是否有一种方法可以添加数据到数据库从一个D ictionary?

帮我

Thanks in Advanced。

回答

2

词典类型不能与实体框架映射。

我不知道你在字典中的关键代表,但您可以创建一个新的中间实体EmployeeEmployeeLeaveEntitlement和辞典键的按键,并在您Employee类映射这是一个集合

public class Foo 
{ 
    [Key] 
    public string DictionaryKey { get; set; } 

    public string EmployeeId { get; set; } 

    public string EmployeeLeaveEntitlementId { get; set; } 

} 

public class Employee 
{ 
    // other properties 

    public ICollection<Foo> Foos { get; set; }  
} 
+0

Ohhh很棒..谢谢Eranga – iJay

相关问题