var temp = "my name is ##user.FName## ##user.LName##";
var user = from u in context.user select u;
var result = temp.Replace("##user.FName## ",user.Fname).Replace("##user.LName##"",user.Lname);
hope this helps...
Cheers!
KK
Please mark as Answer if post helps in resolving your issue
My Site
if i do that than value in temp will remain as string and user data which i fetched from EF 5.0 and database will not be placed.
I could not understand exactly what u mean by that... the value of temp will be replaced by value from database after replace operation...
instead of storing the result of replace in some new variable, you can store it back in temp
var temp = "my name is ##user.FName## ##user.LName##";
var user = from u in context.user select u;
temp = temp.Replace("##user.FName## ",user.Fname).Replace("##user.LName##"",user.Lname);
hope this helps...
Cheers!
KK
Please mark as Answer if post helps in resolving your issue
My Site
first their is a mistake in code segment ..... a extra quotation in it ...
this code will work fine but it require me to write code for each any every column exist in every table.
following might explain problem in the code
//if i have 20 table with 20 columns in each
temp = temp.Replace("##user.FName##",user.Fname).Replace("##user.LName##",user.Lname)// to many replace methods...............
//then i have to write replace part for each part .... //and if any column name changed in future then //it will require me to add or update those replace methods everytime
As far as I see, it seems that you wanna dynamically combine to a whole SQL string and pass this to EntityFramework as its parameter to do searching. So there are mainly two parts:
1) You can use CreateQuery<T> in LINQ-TO-ENTITY, here's the sample:
using (AdventureWorksEntities advWorksContext =
new AdventureWorksEntities())
{
try
{
string queryString =
@"SELECT VALUE Contact FROM AdventureWorksEntities.Contact
AS Contact WHERE Contact.FirstName = @fn";
ObjectQuery<Contact> contactQuery =
advWorksContext.CreateQuery<Contact>(queryString,
new ObjectParameter("fn", "Frances"));
// Iterate through the collection of Contact items.
foreach (Contact result in contactQuery)
Console.WriteLine("First Name: {0}, Last Name: {1}",
result.FirstName, result.LastName);
}
catch (EntitySqlException ex)
{
Console.WriteLine(ex.ToString());
}
}
2) You can also try to use the 3-rd party called Dynamic LINQ, you can also download the sample here:
newbiefreak
Member
468 Points
214 Posts
is it possible to parse value in LINQ?
Dec 07, 2012 10:50 AM|LINK
i am returning a record which contain following result
i want to replace #### parts with its values for example
but main problem come here that #### part could belong to different table. and i need to parse it accordingly.
i have placed table name and column which will help in parsing it. is it possible by a LINQ query ? any solution for this situation ?
kedarrkulkar...
All-Star
34503 Points
5553 Posts
Re: is it possible to parse value in LINQ?
Dec 07, 2012 10:56 AM|LINK
is it what u r looking for?
var temp = "my name is ##user.FName## ##user.LName##"; var user = from u in context.user select u; var result = temp.Replace("##user.FName## ",user.Fname).Replace("##user.LName##"",user.Lname);hope this helps...
KK
Please mark as Answer if post helps in resolving your issue
My Site
newbiefreak
Member
468 Points
214 Posts
Re: is it possible to parse value in LINQ?
Dec 07, 2012 11:01 AM|LINK
nope
if i do that than value in temp will remain as string and user data which i fetched from EF 5.0 and database will not be placed.
need a parsing method which help me dynamically set values by database result
kedarrkulkar...
All-Star
34503 Points
5553 Posts
Re: is it possible to parse value in LINQ?
Dec 07, 2012 11:11 AM|LINK
I could not understand exactly what u mean by that... the value of temp will be replaced by value from database after replace operation...
instead of storing the result of replace in some new variable, you can store it back in temp
var temp = "my name is ##user.FName## ##user.LName##"; var user = from u in context.user select u; temp = temp.Replace("##user.FName## ",user.Fname).Replace("##user.LName##"",user.Lname);hope this helps...
KK
Please mark as Answer if post helps in resolving your issue
My Site
newbiefreak
Member
468 Points
214 Posts
Re: is it possible to parse value in LINQ?
Dec 07, 2012 11:28 AM|LINK
first their is a mistake in code segment ..... a extra quotation in it ...
this code will work fine but it require me to write code for each any every column exist in every table.
following might explain problem in the code
//if i have 20 table with 20 columns in each temp = temp.Replace("##user.FName##",user.Fname).Replace("##user.LName##",user.Lname)// to many replace methods...............Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: is it possible to parse value in LINQ?
Dec 08, 2012 02:56 AM|LINK
Hello,
As far as I see, it seems that you wanna dynamically combine to a whole SQL string and pass this to EntityFramework as its parameter to do searching. So there are mainly two parts:
1) You can use CreateQuery<T> in LINQ-TO-ENTITY, here's the sample:
using (AdventureWorksEntities advWorksContext = new AdventureWorksEntities()) { try { string queryString = @"SELECT VALUE Contact FROM AdventureWorksEntities.Contact AS Contact WHERE Contact.FirstName = @fn"; ObjectQuery<Contact> contactQuery = advWorksContext.CreateQuery<Contact>(queryString, new ObjectParameter("fn", "Frances")); // Iterate through the collection of Contact items. foreach (Contact result in contactQuery) Console.WriteLine("First Name: {0}, Last Name: {1}", result.FirstName, result.LastName); } catch (EntitySqlException ex) { Console.WriteLine(ex.ToString()); } }2) You can also try to use the 3-rd party called Dynamic LINQ, you can also download the sample here:
http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx