Skip to main content
deleted 9 characters in body
Source Link
GEOCHET
  • 21.3k
  • 15
  • 78
  • 99

I have a doubt, sometime I made this conversion from DataTable to List<T>:

  List<EDog> lstDogs = (from drRow in dsDogs.Tables[0].AsEnumerable()
                        select new EDog()
                        {
                            intIdDog = drRow.Field<int>("IdDog"),
                            intIdOwner = drRow.Field<int?>("IdOwner"),
                            intAge = drRow.Field<int>("Age"),
                            strName = drRow.Field<string>("Name")
                       }).ToList();

This worked fine, but now I'm thinking about doing it generic, so that any type of DataSet could be converted to a strongly typed list.

How could I make it generic? maybe a delegate surrounding this part and creating the object?

new EDog()
{
    intIdDog = drRow.Field<int>("IdDog"),
    intIdOwner = drRow.Field<int?>("IdOwner"),
    intAge = drRow.Field<int>("Age"),
    strName = drRow.Field<string>("Name")
}

I tried it but get an error:

select (lambda) expected....

Any suggestion?

The reason why I need this is because each DataRow of the result, needs to be converted to an Entity for better manipulation.

Thanks.

I have a doubt, sometime I made this conversion from DataTable to List<T>:

  List<EDog> lstDogs = (from drRow in dsDogs.Tables[0].AsEnumerable()
                        select new EDog()
                        {
                            intIdDog = drRow.Field<int>("IdDog"),
                            intIdOwner = drRow.Field<int?>("IdOwner"),
                            intAge = drRow.Field<int>("Age"),
                            strName = drRow.Field<string>("Name")
                       }).ToList();

This worked fine, but now I'm thinking about doing it generic, so that any type of DataSet could be converted to a strongly typed list.

How could I make it generic? maybe a delegate surrounding this part and creating the object?

new EDog()
{
    intIdDog = drRow.Field<int>("IdDog"),
    intIdOwner = drRow.Field<int?>("IdOwner"),
    intAge = drRow.Field<int>("Age"),
    strName = drRow.Field<string>("Name")
}

I tried it but get an error:

select (lambda) expected....

Any suggestion?

The reason why I need this is because each DataRow of the result, needs to be converted to an Entity for better manipulation.

Thanks.

I have a doubt, sometime I made this conversion from DataTable to List<T>:

  List<EDog> lstDogs = (from drRow in dsDogs.Tables[0].AsEnumerable()
                        select new EDog()
                        {
                            intIdDog = drRow.Field<int>("IdDog"),
                            intIdOwner = drRow.Field<int?>("IdOwner"),
                            intAge = drRow.Field<int>("Age"),
                            strName = drRow.Field<string>("Name")
                       }).ToList();

This worked fine, but now I'm thinking about doing it generic, so that any type of DataSet could be converted to a strongly typed list.

How could I make it generic? maybe a delegate surrounding this part and creating the object?

new EDog()
{
    intIdDog = drRow.Field<int>("IdDog"),
    intIdOwner = drRow.Field<int?>("IdOwner"),
    intAge = drRow.Field<int>("Age"),
    strName = drRow.Field<string>("Name")
}

I tried it but get an error:

select (lambda) expected....

Any suggestion?

The reason why I need this is because each DataRow of the result, needs to be converted to an Entity for better manipulation.

deleted 428 characters in body; edited tags
Source Link
abatishchev
  • 100.7k
  • 88
  • 303
  • 443

I have a doubt, sometime I made this conversion from DataTableDataTable to List (C# code)List<T>:

  List<EDog> lstDogs = (from drRow in dsDogs.Tables[0].AsEnumerable()
                                  select
                                      new EDog()
                                          {
                                              intIdDog = drRow.Field<int>("IdDog"),
                                              intIdOwner = drRow.Field<int?>("IdOwner"),
                                              intAge = drRow.Field<int>("Age"),
                                              strName = drRow.Field<string>("Name")
                                          }).ToList();
new EDog()
                                          {
                                              intIdDog = drRow.Field<int>("IdDog"),
                                              intIdOwner = drRow.Field<int?>("IdOwner"),
                                              intAge = drRow.Field<int>("Age"),
                                              strName = drRow.Field<string>("Name")
                                          }

I have a doubt, sometime I made this conversion from DataTable to List (C# code):

  List<EDog> lstDogs = (from drRow in dsDogs.Tables[0].AsEnumerable()
                                  select
                                      new EDog()
                                          {
                                              intIdDog = drRow.Field<int>("IdDog"),
                                              intIdOwner = drRow.Field<int?>("IdOwner"),
                                              intAge = drRow.Field<int>("Age"),
                                              strName = drRow.Field<string>("Name")
                                          }).ToList();
new EDog()
                                          {
                                              intIdDog = drRow.Field<int>("IdDog"),
                                              intIdOwner = drRow.Field<int?>("IdOwner"),
                                              intAge = drRow.Field<int>("Age"),
                                              strName = drRow.Field<string>("Name")
                                          }

I have a doubt, sometime I made this conversion from DataTable to List<T>:

  List<EDog> lstDogs = (from drRow in dsDogs.Tables[0].AsEnumerable()
                        select new EDog()
                        {
                            intIdDog = drRow.Field<int>("IdDog"),
                            intIdOwner = drRow.Field<int?>("IdOwner"),
                            intAge = drRow.Field<int>("Age"),
                            strName = drRow.Field<string>("Name")
                       }).ToList();
new EDog()
{
    intIdDog = drRow.Field<int>("IdDog"),
    intIdOwner = drRow.Field<int?>("IdOwner"),
    intAge = drRow.Field<int>("Age"),
    strName = drRow.Field<string>("Name")
}
edited tags
Link
Chris McCall
  • 10.4k
  • 9
  • 51
  • 83
added 14 characters in body
Source Link
lidermin
  • 2.8k
  • 11
  • 44
  • 49
Loading
Source Link
lidermin
  • 2.8k
  • 11
  • 44
  • 49
Loading