本文介绍了实体框架将多列映射到C#复合类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表,我使用四列作为主键:Major,Minor,MajorRevision,MinorRevision。我正在使用Entity Framework 6.1 Code-First懒惰加载,有人可以给我一个例子,我可以如何将这些列映射到ac#System.Version类型?
解决方案
例如:
public class TableV {
public int Major {get;组; }
public int Minor {get;组; }
public int MajorRevision {get;组; }
public int MinorRevision {get;组;
[NotMapped]
System.Version Version {
get {return new Version(Major,Minor,MajorRevision,MinorRevision}
set {Major = value.Major ; Minor = value.Minor; MajorRevision = value.MajorRevision; MinorRevision = value.MinorRevision;}
}
}
,但您不能在查询中使用版本。
I have a table where I use four columns as the primary key: Major, Minor, MajorRevision, MinorRevision.
I'm using Entity Framework 6.1 Code-First lazy loading, can someone give me an example of how I can map those columns to a c# System.Version type?
解决方案
for example:
public class TableV {
public int Major { get; set; }
public int Minor { get; set; }
public int MajorRevision { get; set; }
public int MinorRevision { get; set; }
[NotMapped]
System.Version Version {
get { return new Version(Major, Minor, MajorRevision, MinorRevision}
set {Major = value.Major; Minor = value.Minor; MajorRevision = value.MajorRevision; MinorRevision = value.MinorRevision; }
}
}
but you can't use Version in queries.
这篇关于实体框架将多列映射到C#复合类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!