I need help with LINQ dynamic building
-
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: :|
-
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: :|
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
-
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
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!! :)