C
C#8mo ago
aca

❔ ✅ Why am I getting error message CS0184?

I am trying to compare the return type of a generic method, which produces the following warning. How does the IDE knows my delegate will never be of that certain return type?
No description
30 Replies
Jimmacle
Jimmacle8mo ago
because what that code is doing is checking if an instance of Type is an instance of int which will never be true you're looking for something like func.Method.ReturnType.IsAssignableTo(typeof(int))
aca
aca8mo ago
Could I switch the func.Method.ReturnType and handle casewise for certain datatypes?
Jimmacle
Jimmacle8mo ago
no, because types aren't constants
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
Jimmacle
Jimmacle8mo ago
also as an aside that using (Con) looks suspicious, do you intend for this method to dispose of a connection it doesn't "own"?
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
aca
aca8mo ago
I have the Con defined as my SqlConnection for the class and I am applying methods for handling CRUD functionality
Jimmacle
Jimmacle8mo ago
right, so if you call this you will dispose your sql connection and it won't work for any future calls
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
aca
aca8mo ago
I am still a newbie and my teacher also said usually this isn't how pushing into a SQL database is done, but it will has to do for now since I don't know any other way unfortunately Basically I am handling CRUD by opening, executing the SQL and closing the connection in many smaller methods
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
aca
aca8mo ago
And I tried to create a generic method accepting a delegate since I either insert a SqlCommand or SqlBulkCopy
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
aca
aca8mo ago
Was this how it was done earlier?
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
aca
aca8mo ago
I have background in engineering so my logic is quite developed and I found this to be the most logical way of doing it with my knowledge so far
Jimmacle
Jimmacle8mo ago
the next level up in terms of abstraction would be using a library like dapper, then even more abstract would be ef core
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
aca
aca8mo ago
Makes sense, I just always try to make my methods generic which sometimes isn't working in my favour sadly
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
Jimmacle
Jimmacle8mo ago
for example, i have this query using EF core and there is 0 actual SQL involved
No description
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
aca
aca8mo ago
I can recognize some LINQ - we have just starting delving into the topic. So basically nowadays one wants to avoid SQL, which is why LINQ is there (to encapsulate queries?)
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
Jimmacle
Jimmacle8mo ago
you still want to understand the SQL, but libraries like EF core have the advantage of providing compile time safety to your queries by writing them in C# against C# models using linq
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
Jimmacle
Jimmacle8mo ago
yeah, that screenshot is technically 2 queries that are composed of some common setup no sql is generated until one of the awaited methods is called then EF core will take that linq expression and figure out what the SQL query should be based on your model then send it and convert the response to whatever object type you asked for
Jimmacle
Jimmacle8mo ago
compared to something like dapper, where you still hand-write the SQL query but it can handle mapping objects to and from C# for you
No description
aca
aca8mo ago
I see - the subject is a bit out of scope for me, but I can understand a large part of it. It seems I just need to be able to put all information regarding the certain topic into a collective understanding Now this I can understand fully Anyways thanks for the help guys, appreciate it. Always great to learn something new !close
Accord
Accord8mo ago
Closed! Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts
❔ ✅ denary -> binary```cs using System.Data; static void Main(string[] args) { string ans = AddBinary(1, 2); Co❔ Entity framework migration problemI have problem with creating the migration. I get this error "The seed entity for entity type 'AuthoCS00012 The type is defined in an assembly that is not referenced. But that assembly it is referenceOtherwise if I remove that reference I am getting more than 100 errors, the moment I add that refereI need little help trying to make something like that clicks for this game to help me build somethinHello, I can't get this program to click as it jumps i try and try it won't click idk why but my py❔ EFCore Interceptor problemIn the MS documentation I see they're using the SaveChanges interceptor as: ```csharp public async V❔ Is Entity Framework still worth usingIt has been a good 10 years or so since I used EF. From what I recall, it was good for code first an❔ question around testing techniques and ressources for itgood evening everyone i recently started learning more in depth about testing tdd ddd and correspon❔ asp.net core sessions data set lost on refreshguys i have a big problem which i've been trying to solve for the past few days, so i'm using ASP.NE✅ Getting Error 400: Invalid Hostname when trying to access application in Docker containerHello, I have a .net 7 application running inside a Docker container. The .NET application has an en❔ Swashbuckle remove SwaggerDocI have two swagger docs and I want one of them to be entirely removed (from the drop down too) based