❔ ✅ 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?
30 Replies
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))
Could I switch the
func.Method.ReturnType
and handle casewise for certain datatypes?no, because types aren't constants
Unknown User•13mo ago
Message Not Public
Sign In & Join Server To View
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•13mo ago
Message Not Public
Sign In & Join Server To View
I have the Con defined as my SqlConnection for the class and I am applying methods for handling CRUD functionality
right, so if you call this you will dispose your sql connection and it won't work for any future calls
Unknown User•13mo ago
Message Not Public
Sign In & Join Server To View
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•13mo ago
Message Not Public
Sign In & Join Server To View
And I tried to create a generic method accepting a delegate since I either insert a SqlCommand or SqlBulkCopy
Unknown User•13mo ago
Message Not Public
Sign In & Join Server To View
Was this how it was done earlier?
Unknown User•13mo ago
Message Not Public
Sign In & Join Server To View
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
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•13mo ago
Message Not Public
Sign In & Join Server To View
Makes sense, I just always try to make my methods generic which sometimes isn't working in my favour sadly
Unknown User•13mo ago
Message Not Public
Sign In & Join Server To View
for example, i have this query using EF core and there is 0 actual SQL involved
Unknown User•13mo ago
Message Not Public
Sign In & Join Server To View
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•13mo ago
Message Not Public
Sign In & Join Server To View
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•13mo ago
Message Not Public
Sign In & Join Server To View
yeah, that screenshot is technically 2 queries that are composed of some common setup
no sql is generated until one of the
await
ed 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 forcompared to something like dapper, where you still hand-write the SQL query but it can handle mapping objects to and from C# for you
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
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.