[英]How to create a class with dynamic property (Expandoobject?)
I have a partial class named Exam. 我有一个名为Exam的局部课程。 The class structure shown as below:
该类的结构如下图所示:
public partial class Exam
{
public string ID { set; get; } //default
public string Name { set; get; } //default
}
After executed the store procedure, the retrieved data should contains one or more test methods as shown as following structure. 执行存储过程后,检索到的数据应包含一种或多种测试方法,如下结构所示。 I would like to put the retrieved data to dynamic object Exam.
我想将检索到的数据放入动态对象考试。 How can I create a dynamic object for object Exam and how can i bind the data to this dynamic object?
如何为对象考试创建动态对象,如何将数据绑定到该动态对象?
ID, Name, Test1, Test2, Test3....
1, Peter, Y, N, Y
1, John, N, Y, Y
public virtual ObjectResult<Exam> sp_exam()
{
return ((IObjectContextAdapter)this).
ObjectContext.ExecuteFunction<Exam>("ConnectionEntities.sp__exam");
}
AFAIK ExpandoObject is just a syntax sugar for a simple dictionary. AFAIK ExpandoObject只是简单字典的语法糖。 So you can write:
所以你可以这样写:
public partial class Exam {
public string ID { set; get; } //default
public string Name { set; get; } //default
public readonly Dictionary<string, object> ExtraProperties = new Dictionary<string, object>();
}
but I guess you just have a bad object model. 但是我猜你只是对象模型不好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.