Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. I need help with LINQ dynamic building

I need help with LINQ dynamic building

Scheduled Pinned Locked Moved LINQ
csharplinqsysadminhelptutorial
3 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PunkIsNotDead
    wrote on last edited by
    #1

    Hi programmers! I would like you to help me! :confused: I'm making an user control with two properties: DataContext and Table name (like LinqDataSource) but I don't know how to transform the String parameter values to the Data Context I use

    protected System.Data.Linq.DataContext _myContext;
    protected String contextName;
    public String Contexto
    {
    set
    {
    string ruta = "~/" + value + ".dbml";
    System.Data.Linq.DataContext dc =
    new System.Data.Linq.DataContext(Server.MapPath(ruta));
    _myContext = dc;//Here i recive the data context
    //Tables equal to 0!! and nothing on it!
    }
    get
    {
    return contextName;
    }
    }

    I've try everything but with no results! :(( Also I've tried getting the table name but if the DataContext load is wrong what should I do?? and the table reading seems don't work too

    public String TableType
    {
    set
    {
    _linqTable = _dataContext.Mapping.GetTables().
    Where(f => f.TableName == value).GetType();//Here the table type
    //isn't TBL_Customers or something. Is IEnumerable Where or
    //something strange
    }
    get
    {
    return _linqTable.FullName;
    }
    }

    Pleaseeeee help me!!!!! :(( :(( :confused: :|

    R 1 Reply Last reply
    0
    • P PunkIsNotDead

      Hi programmers! I would like you to help me! :confused: I'm making an user control with two properties: DataContext and Table name (like LinqDataSource) but I don't know how to transform the String parameter values to the Data Context I use

      protected System.Data.Linq.DataContext _myContext;
      protected String contextName;
      public String Contexto
      {
      set
      {
      string ruta = "~/" + value + ".dbml";
      System.Data.Linq.DataContext dc =
      new System.Data.Linq.DataContext(Server.MapPath(ruta));
      _myContext = dc;//Here i recive the data context
      //Tables equal to 0!! and nothing on it!
      }
      get
      {
      return contextName;
      }
      }

      I've try everything but with no results! :(( Also I've tried getting the table name but if the DataContext load is wrong what should I do?? and the table reading seems don't work too

      public String TableType
      {
      set
      {
      _linqTable = _dataContext.Mapping.GetTables().
      Where(f => f.TableName == value).GetType();//Here the table type
      //isn't TBL_Customers or something. Is IEnumerable Where or
      //something strange
      }
      get
      {
      return _linqTable.FullName;
      }
      }

      Pleaseeeee help me!!!!! :(( :(( :confused: :|

      R Offline
      R Offline
      Rashmi_Karnam
      wrote on last edited by
      #2

      Remove Server.MapPath() from DataContext. Directly provide the string ruta in DataContext. It will work. Hope u have tables in .dbml file. OR Define a Connection string in Web.Config file and link it with DBML file. Then assign Connection String to DataContext instead of .dbml file path. Ex : DataAccessDataContext cpContext = new DataAccessDataContext(ConfigurationManager.ConnectionStrings["CustomerPortalConnectionString"].ToString()); where DataAccess is the DBML file name. (DataAccess.dbml)

      Rashmi.M.K

      P 1 Reply Last reply
      0
      • R Rashmi_Karnam

        Remove Server.MapPath() from DataContext. Directly provide the string ruta in DataContext. It will work. Hope u have tables in .dbml file. OR Define a Connection string in Web.Config file and link it with DBML file. Then assign Connection String to DataContext instead of .dbml file path. Ex : DataAccessDataContext cpContext = new DataAccessDataContext(ConfigurationManager.ConnectionStrings["CustomerPortalConnectionString"].ToString()); where DataAccess is the DBML file name. (DataAccess.dbml)

        Rashmi.M.K

        P Offline
        P Offline
        PunkIsNotDead
        wrote on last edited by
        #3

        That would work if I use 'DataAccessDataContext' (a defined datacontext) I understand. But in my case I want to make it more generic. Using the base class inherited (DataContext) of all .dbml files! It doesn't work like I've tried. :(( Maybe there is some way but was out of ideas so I've used a SqlDataAdapter to fill the query and that's all!! but thanks for your help!! :)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups