3

I want fill the dataset in asp.net web application using Entity Framework. I am not familier with Entity Framework please help me.

How to create dataset and how to fill dataset?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Victor Athoti.
  • 829
  • 9
  • 22
  • 49
  • 3
    The whole point of EF is that you **don't** have to deal with DataSet's rows/columns structure, but instead, you get nice .NET objects, properties populated, from your EF code... – marc_s Jun 25 '11 at 05:34

4 Answers4

5

You do not usualy use EF to work with DataSet objects.

If you are interested in the standanrd way of populating DataSet, the following are some articles and tutorials that may help you working with DataSet objects:

Working with Datasets in Visual Studio

HOW TO: Create and Use a Typed DataSet by Using Visual C# .NET

Introduction to strongly Typed Data Sets

The C# Station ADO.NET Tutorial

If you are interested in working with Entity Framework, the following videos set may help:

Practical Entity Framework for C#: Explore Entity Framework

You can always use search engines to further searching for tutorials, guides and samples ..

Akram Shahda
  • 14,655
  • 4
  • 45
  • 65
  • 2
    And this is related to Entity Framework how? The original question was about filling data sets from Entity Framework... – marc_s Jun 25 '11 at 05:40
  • 1
    @marc_s: OPs do not always know what they really needs .. I hope I've put him on the right direction. – Akram Shahda Jun 25 '11 at 05:42
  • I am getting result using linq query.I want to bind this linq query result to the dataset how can i bind linq query result to dataset? – Victor Athoti. Jun 25 '11 at 05:57
  • 1
    @user737497: You dont need a `DataSet` to show the data on your _UI_ controls. Why do you want to use `DataSet` here? – Akram Shahda Jun 25 '11 at 06:16
  • I want Gridview sorting when i click tje gridview header text for that i want need dta set to assign the table to the dataview control – Victor Athoti. Jun 25 '11 at 06:43
2

you can populate your dataset with the following code snippests this question is already asked on stackoverflow.com and answered

you can find Populate a DataSet using Context - Entity Framework 4 here

so i just copy from there and paste here for you

     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);
}
Community
  • 1
  • 1
rahularyansharma
  • 11,156
  • 18
  • 79
  • 135
  • 1
    **WHY** on earth would you want to do this?? You already **have** your nice .NET object - **WHY** kludge those back into a DataTable/DataRow schema??? That's like 20 steps back in time... – marc_s Jun 25 '11 at 05:35
  • Why I need to use data set because I need sorting the grid when i click header text it should be in asc or desc if it is asc it should goes desc for that i need to use default view for grid so i need to bind linq query result to the data set please help me..... – Victor Athoti. Jun 25 '11 at 05:53
  • @user737497: you can achieve this by binding a `List` directly to your grid - there's **absolutely** no need to convert back to a DataSet/DataTable just for this!! You need to read up more on Entity Framework and how to use it to databind to UI controls.... – marc_s Jun 25 '11 at 06:44
  • Ok... is it possible to assign the linq query to a data table – Victor Athoti. Jun 25 '11 at 06:59
0

@Victor, From looking at the dates, I'm late to the party. If you are reading this now, what these folks are trying to say is that you are mixing technologies unneccessarily. The ADO.Net objects have essentially been replaced by the EntityFramework, beginning in .Net 3.5.

To answer the question posed on 6/25/2011, the actual code would be something like this:

List results = SomeQueryResults.ToList();

And that's about it. Most of the rest of the work is done by the grid. you might have to override the OrderBy() function, but that might be it.

0
 DataTable dt = new DataTable();
 dt.Columns.Add("ID", typeof(int));
 dt.Columns.Add("Name", typeof(string));
 DataSet ds = new DataSet();
 ds.Tables.Add(dt);
thevan
  • 10,052
  • 53
  • 137
  • 202