Entity framework 6 IQueryable does not update with separate calls
up vote
1
down vote
favorite
I have an unusual problem where by if I make separate calls to an IQueryable the initial call that creates the IQueryable will generate SQL specific to the first call. This can be seen when debugging and observing the internal query.
When I make inline calls such as:
IQueryable<TableEntity> tEnt = dbCtx.table.AsNoTracking().Include(t=> t.someRefData).Where(t => t.Id >= 10);
this produces the correct internal SQL query.
However If I dynamically make the query with separate distinct calls such as:
IQueryable<TableEntity> tEnt = dbCtx.table.AsNoTracking();
tEnt.Include(t=> t.someRefData);
tEnt.Where(t => t.Id >= 10);
The internal SQL query does not update beyond the declaration of tEnt to reflect these preceeding calls.
Have I total mis-understood how IQueryable works?
linq entity-framework-6 iqueryable
add a comment |
up vote
1
down vote
favorite
I have an unusual problem where by if I make separate calls to an IQueryable the initial call that creates the IQueryable will generate SQL specific to the first call. This can be seen when debugging and observing the internal query.
When I make inline calls such as:
IQueryable<TableEntity> tEnt = dbCtx.table.AsNoTracking().Include(t=> t.someRefData).Where(t => t.Id >= 10);
this produces the correct internal SQL query.
However If I dynamically make the query with separate distinct calls such as:
IQueryable<TableEntity> tEnt = dbCtx.table.AsNoTracking();
tEnt.Include(t=> t.someRefData);
tEnt.Where(t => t.Id >= 10);
The internal SQL query does not update beyond the declaration of tEnt to reflect these preceeding calls.
Have I total mis-understood how IQueryable works?
linq entity-framework-6 iqueryable
3
Include
andWhere
return newIQueryable
objects, you are discarding them.
– DavidG
2 days ago
1
Oh im so having a derp moment ofcourse they do. The calls dont apply to the calling object only create based on what was refered to it.
– Gelion
2 days ago
Btw. a IQueryable is a kind of concatenation of commands. Is used similar to IEnumerable, but the concated commands are not called until the IQueryable is converted into an object (.singe(); .first(); singleOrDefault(); .firstOrDefault()), into an array or into an IEnumerable (e.g. .ToList() ). befor that conversation it is just a command. Also: you have to make the call before you close your container, or you will get an exception, if you try to run your concatinated commands on a closed connection
– Horitsu
2 days ago
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have an unusual problem where by if I make separate calls to an IQueryable the initial call that creates the IQueryable will generate SQL specific to the first call. This can be seen when debugging and observing the internal query.
When I make inline calls such as:
IQueryable<TableEntity> tEnt = dbCtx.table.AsNoTracking().Include(t=> t.someRefData).Where(t => t.Id >= 10);
this produces the correct internal SQL query.
However If I dynamically make the query with separate distinct calls such as:
IQueryable<TableEntity> tEnt = dbCtx.table.AsNoTracking();
tEnt.Include(t=> t.someRefData);
tEnt.Where(t => t.Id >= 10);
The internal SQL query does not update beyond the declaration of tEnt to reflect these preceeding calls.
Have I total mis-understood how IQueryable works?
linq entity-framework-6 iqueryable
I have an unusual problem where by if I make separate calls to an IQueryable the initial call that creates the IQueryable will generate SQL specific to the first call. This can be seen when debugging and observing the internal query.
When I make inline calls such as:
IQueryable<TableEntity> tEnt = dbCtx.table.AsNoTracking().Include(t=> t.someRefData).Where(t => t.Id >= 10);
this produces the correct internal SQL query.
However If I dynamically make the query with separate distinct calls such as:
IQueryable<TableEntity> tEnt = dbCtx.table.AsNoTracking();
tEnt.Include(t=> t.someRefData);
tEnt.Where(t => t.Id >= 10);
The internal SQL query does not update beyond the declaration of tEnt to reflect these preceeding calls.
Have I total mis-understood how IQueryable works?
linq entity-framework-6 iqueryable
linq entity-framework-6 iqueryable
asked 2 days ago
Gelion
152313
152313
3
Include
andWhere
return newIQueryable
objects, you are discarding them.
– DavidG
2 days ago
1
Oh im so having a derp moment ofcourse they do. The calls dont apply to the calling object only create based on what was refered to it.
– Gelion
2 days ago
Btw. a IQueryable is a kind of concatenation of commands. Is used similar to IEnumerable, but the concated commands are not called until the IQueryable is converted into an object (.singe(); .first(); singleOrDefault(); .firstOrDefault()), into an array or into an IEnumerable (e.g. .ToList() ). befor that conversation it is just a command. Also: you have to make the call before you close your container, or you will get an exception, if you try to run your concatinated commands on a closed connection
– Horitsu
2 days ago
add a comment |
3
Include
andWhere
return newIQueryable
objects, you are discarding them.
– DavidG
2 days ago
1
Oh im so having a derp moment ofcourse they do. The calls dont apply to the calling object only create based on what was refered to it.
– Gelion
2 days ago
Btw. a IQueryable is a kind of concatenation of commands. Is used similar to IEnumerable, but the concated commands are not called until the IQueryable is converted into an object (.singe(); .first(); singleOrDefault(); .firstOrDefault()), into an array or into an IEnumerable (e.g. .ToList() ). befor that conversation it is just a command. Also: you have to make the call before you close your container, or you will get an exception, if you try to run your concatinated commands on a closed connection
– Horitsu
2 days ago
3
3
Include
and Where
return new IQueryable
objects, you are discarding them.– DavidG
2 days ago
Include
and Where
return new IQueryable
objects, you are discarding them.– DavidG
2 days ago
1
1
Oh im so having a derp moment ofcourse they do. The calls dont apply to the calling object only create based on what was refered to it.
– Gelion
2 days ago
Oh im so having a derp moment ofcourse they do. The calls dont apply to the calling object only create based on what was refered to it.
– Gelion
2 days ago
Btw. a IQueryable is a kind of concatenation of commands. Is used similar to IEnumerable, but the concated commands are not called until the IQueryable is converted into an object (.singe(); .first(); singleOrDefault(); .firstOrDefault()), into an array or into an IEnumerable (e.g. .ToList() ). befor that conversation it is just a command. Also: you have to make the call before you close your container, or you will get an exception, if you try to run your concatinated commands on a closed connection
– Horitsu
2 days ago
Btw. a IQueryable is a kind of concatenation of commands. Is used similar to IEnumerable, but the concated commands are not called until the IQueryable is converted into an object (.singe(); .first(); singleOrDefault(); .firstOrDefault()), into an array or into an IEnumerable (e.g. .ToList() ). befor that conversation it is just a command. Also: you have to make the call before you close your container, or you will get an exception, if you try to run your concatinated commands on a closed connection
– Horitsu
2 days ago
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
tEnt = tEnt.Include(t=> t.someRefData);
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
tEnt = tEnt.Include(t=> t.someRefData);
add a comment |
up vote
1
down vote
accepted
tEnt = tEnt.Include(t=> t.someRefData);
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
tEnt = tEnt.Include(t=> t.someRefData);
tEnt = tEnt.Include(t=> t.someRefData);
edited 2 days ago
Logan
2,08932856
2,08932856
answered 2 days ago
Horitsu
206210
206210
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53373692%2fentity-framework-6-iqueryable-does-not-update-with-separate-calls%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
Include
andWhere
return newIQueryable
objects, you are discarding them.– DavidG
2 days ago
1
Oh im so having a derp moment ofcourse they do. The calls dont apply to the calling object only create based on what was refered to it.
– Gelion
2 days ago
Btw. a IQueryable is a kind of concatenation of commands. Is used similar to IEnumerable, but the concated commands are not called until the IQueryable is converted into an object (.singe(); .first(); singleOrDefault(); .firstOrDefault()), into an array or into an IEnumerable (e.g. .ToList() ). befor that conversation it is just a command. Also: you have to make the call before you close your container, or you will get an exception, if you try to run your concatinated commands on a closed connection
– Horitsu
2 days ago