2

I have the method below which I am using to fetch data

    public async Task<Mydata> GetMyData(int myId)
    {
        return await DbContext.Data
            .Where(x => x.ParentId == myId || x.ParentId == null) && 
            x.status != FileStatus.Testing && x.status != FileStatus.Commanding);
    }

All I get is the error below. Is this wrong?

ArgumentNullException

'IQueryable<File>' does not contain a definition for 'GetAwaiter' and no accessible extension method 'GetAwaiter' accepting a first argument of type 'IQueryable<Mydata>' could be found (are you missing a using directive or an assembly reference?)

How can i correct this?

1 Answer 1

2

There's no need for async/await here, because nothing asynchronous is happening. The code in the method appears trying to return an IQueryable of something called Mydata (whatever the model type in DbContext.Data is). So just return that:

public IQueryable<Mydata> GetMyData(int myId)
{
    return DbContext.Data
        .Where(x => (x.ParentId == myId || x.ParentId == null) && 
        x.status != FileStatus.Testing && x.status != FileStatus.Commanding);
}

Edit: You also had mis-matched parentheses, the code posted was invalid. I've matched the parentheses, though can't guarantee if the resulting logic is what you intend. Debugging will help you narrow that down though.

Sign up to request clarification or add additional context in comments.

13 Comments

I don't see any difference in the code i pasted and what you corrected apart from the await. This does not work.
@user2320476: Define "does not work". The difference is removing the async/await.
All i get is the name x does not exist in the current context
@user2320476: Which is a different error. Looking at the code, you appear to also have a syntax error from mismatched parentheses. I'll update the answer now.
This is a similar query that works in sql. select * from dbo.data where (parentid = '2215' or parentid is null) and statusId != 7 and statusId != 8
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.