Enums EF 5带导航的枚举
我正在尝试将Enum支持与ef5和dot.NET 4.5结合使用 我的情况如下 POCO: 如果未将tbl_pp_MessagePriority_MessagePriorityId添加到插入中,则可以 在使用ENUM支持时,如何首先将navigaion保留在EF代码中?是否有DataAnnotation或映射API 请张贴您可能有的任何建议。此项目未使用EDMX/T4模板 工作POCO:Enums EF 5带导航的枚举,enums,entity-framework-5,entity-relationship,Enums,Entity Framework 5,Entity Relationship,我正在尝试将Enum支持与ef5和dot.NET 4.5结合使用 我的情况如下 POCO: 如果未将tbl_pp_MessagePriority_MessagePriorityId添加到插入中,则可以 在使用ENUM支持时,如何首先将navigaion保留在EF代码中?是否有DataAnnotation或映射API 请张贴您可能有的任何建议。此项目未使用EDMX/T4模板 工作POCO: public partial class tbl_pp_Message { //p
public partial class tbl_pp_Message
{
//public tbl_pp_Message()
//{
// this.tbl_pp_MessageDistribution = new List<tbl_pp_MessageDistribution>();
//}
public int MessageId { get; set; }
public string Subject { get; set; }
public string From { get; set; }
public string Body { get; set; }
public MessagePriorityEnum PriorityId { get; set; }
public System.DateTime CreateDate { get; set; }
public int CreateById { get; set; }
//[ForeignKey("PriorityId")]
//public virtual tbl_pp_MessagePriority tbl_pp_MessagePriority { get; set; }
//public virtual ICollection<tbl_pp_MessageDistribution> tbl_pp_MessageDistribution { get; set; }
}
public partial class tbl_pp_MessagePriority
{
//public tbl_pp_MessagePriority()
//{
// this.tbl_pp_Message = new List<tbl_pp_Message>();
//}
public int MessagePriorityId { get; set; }
public string Description { get; set; }
public Nullable<int> DisplayOrder { get; set; }
public bool ShowAlert { get; set; }
//public virtual ICollection<tbl_pp_Message> tbl_pp_Message { get; set; }
}
公共部分类tbl\u pp\u消息
{
//公共tbl_pp_消息()
//{
//this.tbl_pp_MessageDistribution=新列表();
//}
public int MessageId{get;set;}
公共字符串主题{get;set;}
来自{get;set;}的公共字符串
公共字符串体{get;set;}
public MessagePriorityEnum PriorityId{get;set;}
public System.DateTime CreateDate{get;set;}
public int CreateById{get;set;}
//[ForeignKey(“PriorityId”)]
//公共虚拟tbl_pp_MessagePriority tbl_pp_MessagePriority{get;set;}
//公共虚拟ICollection tbl_pp_MessageDistribution{get;set;}
}
公共部分类tbl\U pp\U消息优先级
{
//公共tbl_pp_MessagePriority()
//{
//this.tbl_pp_Message=新列表();
//}
public int MessagePriorityId{get;set;}
公共字符串说明{get;set;}
公共可为空的显示顺序{get;set;}
公共bool ShowAlert{get;set;}
//公共虚拟ICollection tbl_pp_消息{get;set;}
}
如果不需要导航,工作POCO就可以了。我缺少的是将查找表主键设置为相同的枚举类型,而不是int 使用枚举和导航操作POCO
public partial class tbl_pp_Message
{
public tbl_pp_Message()
{
this.tbl_pp_MessageAction = new List<tbl_pp_MessageAction>();
this.tbl_pp_MessageAttachment = new List<tbl_pp_MessageAttachment>();
this.tbl_pp_MessageDistribution = new List<tbl_pp_MessageDistribution>();
}
public int MessageId { get; set; }
public string Subject { get; set; }
public string From { get; set; }
public string Body { get; set; }
public MessageTypeEnum TypeId { get; set; }
public System.DateTime CreateDate { get; set; }
public int CreateById { get; set; }
[ForeignKey("TypeId")]
public virtual tbl_pp_MessageType tbl_pp_MessageType { get; set; }
public virtual ICollection<tbl_pp_MessageAction> tbl_pp_MessageAction { get; set; }
public virtual ICollection<tbl_pp_MessageAttachment> tbl_pp_MessageAttachment { get; set; }
public virtual ICollection<tbl_pp_MessageDistribution> tbl_pp_MessageDistribution { get; set; }
}
public partial class tbl_pp_MessageType
{
public tbl_pp_MessageType()
{
this.tbl_pp_Message = new List<tbl_pp_Message>();
}
[Key]
public MessageTypeEnum MessageTypeId { get; set; }
public string Description { get; set; }
public Nullable<int> DisplayOrder { get; set; }
public bool ShowAlert { get; set; }
public virtual ICollection<tbl_pp_Message> tbl_pp_Message { get; set; }
}
公共部分类tbl\u pp\u消息
{
公共tbl_pp_消息()
{
this.tbl_pp_MessageAction=新列表();
this.tbl_pp_MessageAttachment=新列表();
this.tbl_pp_MessageDistribution=新列表();
}
public int MessageId{get;set;}
公共字符串主题{get;set;}
来自{get;set;}的公共字符串
公共字符串体{get;set;}
public MessageTypeEnum TypeId{get;set;}
public System.DateTime CreateDate{get;set;}
public int CreateById{get;set;}
[外键(“类型ID”)]
公共虚拟tbl_pp_消息类型tbl_pp_消息类型{get;set;}
公共虚拟ICollection tbl_pp_MessageAction{get;set;}
公共虚拟ICollection tbl_pp_MessageAttachment{get;set;}
公共虚拟ICollection tbl_pp_MessageDistribution{get;set;}
}
公共部分类tbl\u pp\u MessageType
{
公共tbl_pp_MessageType()
{
this.tbl_pp_Message=新列表();
}
[关键]
public MessageTypeEnum MessageTypeId{get;set;}
公共字符串说明{get;set;}
公共可为空的显示顺序{get;set;}
公共bool ShowAlert{get;set;}
公共虚拟ICollection tbl_pp_消息{get;set;}
}
insert [dbo].[tbl_pp_Message]
([Subject],
[From],
[Body],
[PriorityId],
[CreateDate],
[CreateById],
[tbl_pp_MessagePriority_MessagePriorityId])
values ('Test ENUM EF Code First 5.0' /* @0 */,
'Daniel.Bivens' /* @1 */,
'Test 01 Enum Body - The Magic Unicorn Edition' /* @2 */,
2 /* @3 */,
'2013-05-23T10:52:09' /* @4 */,
5 /* @5 */,
null)
select [MessageId]
from [dbo].[tbl_pp_Message]
where @@ROWCOUNT > 0
and [MessageId] = scope_identity()
public partial class tbl_pp_Message
{
//public tbl_pp_Message()
//{
// this.tbl_pp_MessageDistribution = new List<tbl_pp_MessageDistribution>();
//}
public int MessageId { get; set; }
public string Subject { get; set; }
public string From { get; set; }
public string Body { get; set; }
public MessagePriorityEnum PriorityId { get; set; }
public System.DateTime CreateDate { get; set; }
public int CreateById { get; set; }
//[ForeignKey("PriorityId")]
//public virtual tbl_pp_MessagePriority tbl_pp_MessagePriority { get; set; }
//public virtual ICollection<tbl_pp_MessageDistribution> tbl_pp_MessageDistribution { get; set; }
}
public partial class tbl_pp_MessagePriority
{
//public tbl_pp_MessagePriority()
//{
// this.tbl_pp_Message = new List<tbl_pp_Message>();
//}
public int MessagePriorityId { get; set; }
public string Description { get; set; }
public Nullable<int> DisplayOrder { get; set; }
public bool ShowAlert { get; set; }
//public virtual ICollection<tbl_pp_Message> tbl_pp_Message { get; set; }
}
public partial class tbl_pp_Message
{
public tbl_pp_Message()
{
this.tbl_pp_MessageAction = new List<tbl_pp_MessageAction>();
this.tbl_pp_MessageAttachment = new List<tbl_pp_MessageAttachment>();
this.tbl_pp_MessageDistribution = new List<tbl_pp_MessageDistribution>();
}
public int MessageId { get; set; }
public string Subject { get; set; }
public string From { get; set; }
public string Body { get; set; }
public MessageTypeEnum TypeId { get; set; }
public System.DateTime CreateDate { get; set; }
public int CreateById { get; set; }
[ForeignKey("TypeId")]
public virtual tbl_pp_MessageType tbl_pp_MessageType { get; set; }
public virtual ICollection<tbl_pp_MessageAction> tbl_pp_MessageAction { get; set; }
public virtual ICollection<tbl_pp_MessageAttachment> tbl_pp_MessageAttachment { get; set; }
public virtual ICollection<tbl_pp_MessageDistribution> tbl_pp_MessageDistribution { get; set; }
}
public partial class tbl_pp_MessageType
{
public tbl_pp_MessageType()
{
this.tbl_pp_Message = new List<tbl_pp_Message>();
}
[Key]
public MessageTypeEnum MessageTypeId { get; set; }
public string Description { get; set; }
public Nullable<int> DisplayOrder { get; set; }
public bool ShowAlert { get; set; }
public virtual ICollection<tbl_pp_Message> tbl_pp_Message { get; set; }
}