C
C#10mo ago
only you know

repository returns unwanted areas

my repo code section is here
C#

public async Task<Follow> GetFollowById(int id)
{
using(var conn = new MySqlConnection(_connectionString))
using(var cmd = conn.CreateCommand())
{
conn.Open();
cmd.CommandText = "SELECT id, followedUsername, user FROM Follow WHERE id = @id";
cmd.Parameters.AddWithValue("@id", id);
using (var reader = cmd.ExecuteReader())
{
if (!reader.Read())
{
return null;
}
return new Follow
{
id = reader.GetInt32(0),
followedUsername = reader.GetString(1),
user = reader.GetString(2)
};
}
}
}
C#

public async Task<Follow> GetFollowById(int id)
{
using(var conn = new MySqlConnection(_connectionString))
using(var cmd = conn.CreateCommand())
{
conn.Open();
cmd.CommandText = "SELECT id, followedUsername, user FROM Follow WHERE id = @id";
cmd.Parameters.AddWithValue("@id", id);
using (var reader = cmd.ExecuteReader())
{
if (!reader.Read())
{
return null;
}
return new Follow
{
id = reader.GetInt32(0),
followedUsername = reader.GetString(1),
user = reader.GetString(2)
};
}
}
}
No description
22 Replies
only you know
only you knowOP10mo ago
my get all function is almost same but returns true body
only you know
only you knowOP10mo ago
here's get all and the response
No description
No description
Angius
Angius10mo ago
Do you await it? Because your first result seems like you serialized a Task As a side note, unless the teacher forbids it, I'd highly recommend using literally anything else than ADO for your database stuff. Dapper would be my recommendation if you still want to write raw SQL
only you know
only you knowOP10mo ago
am I using ado rn? don't know the name exactly sorry
Angius
Angius10mo ago
I believe so, yeah. Using the reader manually and all that jazz
only you know
only you knowOP10mo ago
yh it has to be async I think
Angius
Angius10mo ago
Well, it is async But are you awaiting it?
only you know
only you knowOP10mo ago
im awaiting here. does it count?
No description
Angius
Angius10mo ago
That is not the method you showed before
only you know
only you knowOP10mo ago
its service layer
Angius
Angius10mo ago
No description
No description
Angius
Angius10mo ago
It's, supposedly, this method causing issues Now you're showing me a completely different one, that also calls a completely different one So, which is it that produces this unexpected output?
only you know
only you knowOP10mo ago
oop wait my bad. I edited the code can you check again?
Angius
Angius10mo ago
It seems perfectly fine Do you await this method, then?
only you know
only you knowOP10mo ago
but the response is contains unwanted areas
only you know
only you knowOP10mo ago
I want to return only result part here
No description
Angius
Angius10mo ago
Do you, or do you not, await the method I mentioned?
only you know
only you knowOP10mo ago
isn't it await?
No description
Angius
Angius10mo ago
And when you call this method?
No description
only you know
only you knowOP10mo ago
or should I make it like this return await new Follow { id = reader.GetInt32(0), followedUsername = reader.GetString(1), user = reader.GetString(2) };
Angius
Angius10mo ago
Is this one awaited? Constructors cannot be asynchronous, so no, you cannot await a constructor
only you know
only you knowOP10mo ago
oh I found my mistake thank you for your await messages
Want results from more Discord servers?
Add your server