GameDataContext dt = new GameDataContext();
Game add = null;
add = from a in Game \\ what should i write here?
where add.NameOppenent = Nametb.Text
select
Your from/select is returning a collection of items (in simple terms) but you are trying to asign that to your "add" variable which is of type "Game" - your from/select does not return one singe "Game" object. Try something like
var temp = from a in dt.Games where add.NameOppenent == Nametb.Text select a;
add = temp.FirstOrDefault();
In the above the code will work out the right type for "temp", and the line below assigns your "add" variable to the first item in the resul (which will be a Game object), or null if the select didn't return anything.
GameDataContext dt = new GameDataContext();
//Game add = null;
var add = from a in Game dt.yourEntities
where a.NameOppenent == Nametb.Text
select a;
Assumption "Game" is your entity class.
"add" type is IEnumerable<Game> automatically assign when using "var add" and "a" class is "Game", "NameOppenent" is one of string property of "Game", "Nametb.Text" is your string.
UrGridView.DataSource = from a in dt.Games
where a.NameOppenent == Nametb.Text
select a; // select new { Column1Name = a.column1, Column2Name = a.column2 } ; try this, if u wanna selective columns
UrGridView.DataBind();
tzahi2010
Member
266 Points
287 Posts
linq using where
May 02, 2012 01:51 PM|LINK
how can i use the where senetnce
GameDataContext dt = new GameDataContext(); Game add = null; add = from a in Game \\ what should i write here? where add.NameOppenent = Nametb.Text selectwhat should i write instead of Game?
Ramesh T
Contributor
5171 Points
833 Posts
Re: linq using where
May 02, 2012 01:57 PM|LINK
U could use any type that implements query pattern.
Below is how u should use where clasue in LINQ
int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; var lowNums = from n in numbers where n < 5 select n;AidyF
Star
9246 Points
1576 Posts
Re: linq using where
May 02, 2012 01:57 PM|LINK
from a in dt.Games?
tzahi2010
Member
266 Points
287 Posts
Re: linq using where
May 02, 2012 01:58 PM|LINK
whats an implements query pattern?
tzahi2010
Member
266 Points
287 Posts
Re: linq using where
May 02, 2012 02:04 PM|LINK
why am i getting an error on this select sentence:
from a in dt.Games where add.NameOppenent == Nametb.Text select a.NameAsker;Cannot implicitly convert type 'System.Linq.IQueryable<string>' to 'Game'. An explicit conversion exists (are you missing a cast?)
Ramesh T
Contributor
5171 Points
833 Posts
Re: linq using where
May 02, 2012 02:05 PM|LINK
In simple terms, U could use objects which implements IEnumerable<T> or IQueryable Interface.
U may need to change ur query as below
var rows = from a in dt.Games where a.NameOppenent == Nametb.Text select a.NameAsker; var nameAsker = rows.FirstOrDefault();AidyF
Star
9246 Points
1576 Posts
Re: linq using where
May 02, 2012 02:09 PM|LINK
Your from/select is returning a collection of items (in simple terms) but you are trying to asign that to your "add" variable which is of type "Game" - your from/select does not return one singe "Game" object. Try something like
In the above the code will work out the right type for "temp", and the line below assigns your "add" variable to the first item in the resul (which will be a Game object), or null if the select didn't return anything.
jsiahaan
Contributor
2550 Points
645 Posts
Re: linq using where
May 02, 2012 02:14 PM|LINK
I am trying to answer based on your code:
GameDataContext dt = new GameDataContext(); //Game add = null; var add = from a in Game dt.yourEntities where a.NameOppenent == Nametb.Text select a;Assumption "Game" is your entity class.
"add" type is IEnumerable<Game> automatically assign when using "var add" and "a" class is "Game", "NameOppenent" is one of string property of "Game", "Nametb.Text" is your string.
Hope this can help
Indonesian Humanitarian Foundation
tzahi2010
Member
266 Points
287 Posts
Re: linq using where
May 02, 2012 02:20 PM|LINK
hello thank u for the help but now i got another question.
how do i add to a listview\gridview the lines which are go right with the sentence "where add.NameOppenent == Nametb.Text"?
Ramesh T
Contributor
5171 Points
833 Posts
Re: linq using where
May 02, 2012 02:24 PM|LINK
Try like this
UrGridView.DataSource = from a in dt.Games where a.NameOppenent == Nametb.Text select a; // select new { Column1Name = a.column1, Column2Name = a.column2 } ; try this, if u wanna selective columns UrGridView.DataBind();