I cant make a full dynamic query in LINQ

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mucahit ikiz

    I cant make a full dynamic query in LINQ


    I cant make a full dynamic query in LINQ

    I have 2 situation methods (only_exp_query , only_tbl_query) those are
    working.

    ....
    using System.Linq.Dyn amic;
    using System.Data.Lin q;
    ....
    string connString = @"Data Source=.;Initia l
    Catalog=Northwi nd;Integrated Security=True";
    DataClasses1Dat aContext db = new
    DataClasses1Dat aContext(connSt ring);
    ....
    private void only_exp_query( )
    {

    Table<Customer_ customer = db.Customers;
    var query = db.Customers
    .Where("City=@0 ", "LONDON")
    .OrderBy("Compa nyName");
    dataGridView1.D ataSource = query;
    }

    private void only_tbl_query( )
    {
    Table<Customer_ customer = db.Customers;

    var query = from tbl in _customer
    select tbl;
    dataGridView1.D ataSource = query;
    }


    But i want to run the script below , but it is not working...

    private void full_query()
    {

    Table<Customer_ customer = db.Customers;
    var query = db.Customers
    .GetTable("Cust omers")
    .Where("City=@0 ", "LONDON")
    .OrderBy("Compa nyName");
    dataGridView1.D ataSource = query;
    }

    and then i can try this below script...

    private void full_query()
    {
    Assembly asm =
    Assembly.GetAss embly(typeof(Da taClasses1DataC ontext));

    var query = db.GetTable(asm .GetType("Custo mer"));
    .Where("City == @0 and Orders.Count >= @1", "London", 10)
    .OrderBy("Compa nyName, City")
    .Select("New(Co mpanyName as Name, Phone)");
    dataGridView1.D ataSource = query;
    }
    but it returns the following error:
    "ArgumentNullEx ception was unhandled ,Value Cannot be null,Parameter Type"
    but i dont know this error.


    WHAT CAN I DO?
    can you help me please


  • Marc Gravell

    #2
    Re: I cant make a full dynamic query in LINQ

    First thought; one of the primary aims of LINQ is to provide things
    like compile-time checking to expressions, and a better development
    experience. By going down a fully dynamic route, you're not really
    getting many of those benefits... so an I ask (out of curiosity) why
    regular LINQ isn't an option here? There may be better ways of doing
    what you want.

    Marc

    Comment

    • Mucahit ikiz

      #3
      Re: I cant make a full dynamic query in LINQ

      This problem was solve.

      that
      Assembly asm = Assembly.GetAss embly(typeof(Da taClasses1DataC ontext));
      var query = db.GetTable(asm .GetType("Custo mer"));

      we change this row
      Table<Customer_ customer = this.Context.Ge tTable( typeof(Customer ) ) as
      Table<Customer> ;"Mucahit ikiz" <mucahit.ikiz@s ifas.com.trwrot e in message
      news:%23pTWEHE4 IHA.1428@TK2MSF TNGP06.phx.gbl. ..
      >
      I cant make a full dynamic query in LINQ
      >
      I have 2 situation methods (only_exp_query , only_tbl_query) those are
      working.
      >
      ...
      using System.Linq.Dyn amic;
      using System.Data.Lin q;
      ...
      string connString = @"Data Source=.;Initia l
      Catalog=Northwi nd;Integrated Security=True";
      DataClasses1Dat aContext db = new
      DataClasses1Dat aContext(connSt ring);
      ...
      private void only_exp_query( )
      {
      >
      Table<Customer_ customer = db.Customers;
      var query = db.Customers
      .Where("City=@0 ", "LONDON")
      .OrderBy("Compa nyName");
      dataGridView1.D ataSource = query;
      }
      >
      private void only_tbl_query( )
      {
      Table<Customer_ customer = db.Customers;
      >
      var query = from tbl in _customer
      select tbl;
      dataGridView1.D ataSource = query;
      }
      >
      >
      But i want to run the script below , but it is not working...
      >
      private void full_query()
      {
      >
      Table<Customer_ customer = db.Customers;
      var query = db.Customers
      .GetTable("Cust omers")
      .Where("City=@0 ", "LONDON")
      .OrderBy("Compa nyName");
      dataGridView1.D ataSource = query;
      }
      >
      and then i can try this below script...
      >
      private void full_query()
      {
      Assembly asm =
      Assembly.GetAss embly(typeof(Da taClasses1DataC ontext));
      >
      var query = db.GetTable(asm .GetType("Custo mer"));
      .Where("City == @0 and Orders.Count >= @1", "London", 10)
      .OrderBy("Compa nyName, City")
      .Select("New(Co mpanyName as Name, Phone)");
      dataGridView1.D ataSource = query;
      }
      but it returns the following error:
      "ArgumentNullEx ception was unhandled ,Value Cannot be null,Parameter Type"
      but i dont know this error.
      >
      >
      WHAT CAN I DO?
      can you help me please
      >

      Comment

      Working...