0

With the reference of this i add a methods in WebForm1.aspx.cs

Reference link

but when i add and build my code then there is error

Extension method must be defined in a top level static class; CustomLINQtoDataSetMethods is a nested class

Extension method must be defined in a top level static class; CustomLINQtoDataSetMethods is a nested class

I do this because i have web method

[WebMethod]
    public static DataTable search_data(DateTime fromdate, DateTime todate, string regiondrop)
    {

        try
        {

            T1 ts = new T1();
            var dq = (from vv in ts.tblVe
                      join rv in ts.tblReg on vv.ID equals rv.ID
                      join re in ts.tblRegi on rv.RID equals re.RID
                      where
                      re.Region == regiondrop
                      && re.StartDate <= fromdate
                      && re.EndDate >= todate
                      orderby
                      vv.ID,
                      rv.OwnerName
                      select new
                      {
                          ID = vv.ID,
                          ownername = rv.OwnerName,
                          RegNo = rv.RegNo,
                          Speed = rv.Speed,
                      });
            var dt = dq.cop();
                     }
        catch (Exception)
        {
            throw new Exception();

        }

    }

when i add this line var dt = dq.cop(); with the reference and answer of this question reference 2 then CopyToDataTable is not in intellisence list

In dq the data is

[0] = { ID = 1, OName = "Khn", RegNo = "AJ-24",Speed = "124" }
[1] = { ID = 2, OName = "hah", RegNo = "AL-91",Speed = "95" }
Community
  • 1
  • 1
SUPER_USER
  • 275
  • 3
  • 16

1 Answers1

1

It tells exactly what the problem is. You have to define extention methods in a public not-nested class. As mentioned on MSDN:

public static class CustomLINQtoDataSetMethods
{
    public static DataTable CopyToDataTable<T>(this IEnumerable<T> source)
    {
        return new ObjectShredder<T>().Shred(source, null, null);
    }

    public static DataTable CopyToDataTable<T>(this IEnumerable<T> source,
                                                DataTable table, LoadOption? options)
    {
        return new ObjectShredder<T>().Shred(source, table, options);
    }    
}

And you've most likely put the CustomLINQtoDataSetMethods inside other class. Make sure it's outside of any other classes and the issue should be fixed.

Ivan Yurchenko
  • 3,762
  • 1
  • 21
  • 35
  • i dont have any other class i have only webform1.aspx.cs – SUPER_USER Jul 15 '16 at 11:55
  • check this link please.. https://onedrive.live.com/edit.aspx?cid=0da6abfef43e7d3d&page=view&resid=DA6ABFEF43E7D3D!511&parId=DA6ABFEF43E7D3D!111&app=Word – SUPER_USER Jul 15 '16 at 12:08
  • this show so many errors.. Error 3 The type or namespace name 'FieldInfo' could not be found (are you missing a using directive or an assembly reference?) Error 4 Cannot implicitly convert type 'System.Reflection.FieldInfo[]' to 'FieldInfo[]' Error 5 The type or namespace name 'PropertyInfo' could not be found (are you missing a using directive or an assembly reference?) – SUPER_USER Jul 16 '16 at 04:32
  • Error 6 Cannot implicitly convert type 'System.Reflection.PropertyInfo[]' to 'PropertyInfo[]' Error 7 Cannot implicitly convert type 'System.Reflection.FieldInfo[]' to 'FieldInfo[]' Error 8 Cannot implicitly convert type 'System.Reflection.PropertyInfo[]' to 'PropertyInfo[]' Error 9 The type or namespace name 'FieldInfo' could not be found (are you missing a using directive or an assembly reference?) Error 10 The type or namespace name 'PropertyInfo' could not be found (are you missing a using directive or an assembly reference?) – SUPER_USER Jul 16 '16 at 04:32
  • Error 11 The type or namespace name 'FieldInfo' could not be found (are you missing a using directive or an assembly reference?) Error 12 The type or namespace name 'PropertyInfo' could not be found (are you missing a using directive or an assembly reference?) Error 13 The type or namespace name 'ObjectShredder' could not be found (are you missing a using directive or an assembly reference?) Error 14 The type or namespace name 'ObjectShredder' could not be found (are you missing a using directive or an assembly reference?) – SUPER_USER Jul 16 '16 at 04:32