填充使用上下文数据集 - 实体框架4 [英] Populate a DataSet using Context - Entity Framework 4

查看:142
本文介绍了填充使用上下文数据集 - 实体框架4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从上下文中的有些数据返回。数据是由 spCmsCategoriesReadHierarchy

我需要从语境采取一切数据和填充我的数据集。我的最终目标是要填充DataSet对象TreeView控件。

任何想法?感谢您的时间和耐心。

 使用(TestHierarchyEntities上下文=新TestHierarchyEntities())
{
    INT N = 0;
    INT16 SL = 1;
    ObjectParameter NN =新ObjectParameter(NN的typeof(INT));    //创建一个数据集,其中添加上下文的结果
    数据集的数据集=新的DataSet(myDataSet);    的foreach(CmsCategory类别context.spCmsCategoriesReadHierarchy(N,SL,NN))
    {
    }
}


解决方案

当然,你可以手动将数据从以上的对象复制到数据集内数据行。

 数据集的数据集=新的DataSet(myDataSet);
dataSet.Tables.Add(新的DataTable());
//设置表列中。的foreach(CmsCategory类别context.spCmsCategoriesReadHierarchy(N,SL,NN))
{
    行的DataRow = dataSet.Tables [0] .NewRow();
    行[A] = categories.A;
    行[B] = categories.B;    dataSet.Tables [0] .Rows.Add(行);
}

如果你不希望在明确的属性复制到数据行,你也可以使用反射来进行复制。

I have some Data returning from a Context. Data has being pulled by spCmsCategoriesReadHierarchy.

I need take all Data from Context and populate my DataSet. My final goal is to populate a TreeView Control with DataSet object.

Any ideas? Thanks for your time and patience.

using (TestHierarchyEntities context = new TestHierarchyEntities())
{
    int n = 0;
    Int16 sl = 1;
    ObjectParameter nn = new ObjectParameter("nn", typeof(int));

    // Create a Data Set where adding the result of context 
    DataSet dataSet = new DataSet("myDataSet");

    foreach (CmsCategory categories in context.spCmsCategoriesReadHierarchy(n,sl,nn))
    {
    }
}

解决方案

Sure, you can manually copy the data over from the object to a data row within the dataset.

DataSet dataSet = new DataSet("myDataSet");
dataSet.Tables.Add(new DataTable());
//Setup the table columns.

foreach (CmsCategory categories in context.spCmsCategoriesReadHierarchy(n,sl,nn))
{
    DataRow row = dataSet.Tables[0].NewRow();
    row["A"] = categories.A;
    row["B"] = categories.B;

    dataSet.Tables[0].Rows.Add(row);
}

If you are not looking to explicitly copy over the properties to the data row, you can also use reflection to do the copying.

这篇关于填充使用上下文数据集 - 实体框架4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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