var or = await _context
.OrganisationID
.FromSqlRaw("SELECT pj.proj_org_id as orgId FROM[mapping].[DataResourceTenancy] as dt JOIN web.Project as pj on dt.drp_projCode = proj_code where drp_amrd_serialNumber like {0} ", deviceName)
.ToListAsync();
When I execute, it is giving me the count not the value. Please help me
You are seeing a Count in the debugger panes because that one of the default properties displayed by a list, because you asked for a list byt calling ToListAsync(). You need to iterate over the list to get the actual objects. Or if you know that there is only ever one object, you could use Single() instead of ToList().
You are seeing a Count in the debugger panes because that one of the default properties displayed by a list, because you asked for a list byt calling ToListAsync(). You need to iterate over the list to get the actual objects. Or if you know that there is only ever one object, you could use Single() instead of ToList().
You are seeing a Count in the debugger panes because that one of the default properties displayed by a list, because you asked for a list byt calling ToListAsync(). You need to iterate over the list to get the actual objects. Or if you know that there is only ever one object, you could use Single() instead of ToList().
Compiler Error CS1061 : 'type' does not contain a definition for 'name' and no accessible extension method 'name' accepting a first argument of type 'type' could be found (are you missing a using directive or an assembly reference?).
the code is like this:
C#:
public async Task<int> GetOrgIdByDeviceName(string deviceName)
{
var or = await _context
.GetOrganisationID
.FromSqlRaw("SELECT OrgId = [dbo].[FcGetOrgIdByDeviceName]({0}) ", deviceName)
.Single();
return or;
}
Are you sure the error is there? The error is talking about a variable name, but there is no such variable there in the code you presented. The variable there is deviceName.
Are you sure the error is there? The error is talking about a variable name, but there is no such variable there in the code you presented. The variable there is deviceName.
*sigh* The issue is that you are trying to await on the returned single object. Since that object has no awaiter because it is not a Task, you get that compile time error which tells you that it can't find the GetAwaiter() method.
The quickest path forward for you is to remove the async/await:
C#:
public int GetOrgIdByDeviceName(string deviceName)
{
return _context
.GetOrganisationID
.FromSqlRaw("SELECT OrgId = [dbo].[FcGetOrgIdByDeviceName]({0}) ", deviceName)
.Single();
}
If you really much have async functionality, then you need to use part of your original code to get the list asynchronously, and then once you have the list, just pull the single object from it.
C#:
public async Task<int> GetOrgIdByDeviceNameAsync(string deviceName)
{
var list = await _context
.GetOrganisationID
.FromSqlRaw("SELECT OrgId = [dbo].[FcGetOrgIdByDeviceName]({0}) ", deviceName)
.ToListAsync();
return list.Single();
}
*sigh* The issue is that you are trying to await on the returned single object. Since that object has no awaiter because it is not a Task, you get that compile time error which tells you that it can't find the GetAwaiter() method.
The quickest path forward for you is to remove the async/await:
C#:
public int GetOrgIdByDeviceName(string deviceName)
{
return _context
.GetOrganisationID
.FromSqlRaw("SELECT OrgId = [dbo].[FcGetOrgIdByDeviceName]({0}) ", deviceName)
.Single();
}
If you really much have async functionality, then you need to use part of your original code to get the list asynchronously, and then once you have the list, just pull the single object from it.
C#:
public async Task<int> GetOrgIdByDeviceNameAsync(string deviceName)
{
var list = await _context
.GetOrganisationID
.FromSqlRaw("SELECT OrgId = [dbo].[FcGetOrgIdByDeviceName]({0}) ", deviceName)
.ToListAsync();
return list.Single();
}
I recommend using int.TryParse() for production code. For quick and dirty code where you are just trying to prototype stuff, use int.Parse() or Convert.ToInt32().
I recommend using int.TryParse() for production code. For quick and dirty code where you are just trying to prototype stuff, use int.Parse() or Convert.ToInt32().
It should be pretty self-explanatory. You are trying to edit code that is currently running. Stop debugging. Edit the code. Recompile. The run with the debugger again.
I'm puzzled why you would need to convert a string to an integer when you already have an integer. The compiler would not have let you start debugging code if your method returned a Task<int> or int[/code] if the result of calling [icode].Single() was not an int.
It should be pretty self-explanatory. You are trying to edit code that is currently running. Stop debugging. Edit the code. Recompile. The run with the debugger again.
The compiler is correct. You should read the documentation sometime before posting a question. Part of being a developer is learning how to read documentation.
It should be pretty self-explanatory. You are trying to edit code that is currently running. Stop debugging. Edit the code. Recompile. The run with the debugger again.
I'm puzzled why you would need to convert a string to an integer when you already have an integer. The compiler would not have let you start debugging code if your method returned a Task<int> or int[/code] if the result of calling [icode].Single() was not an int.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.