c# - How to pass method (class) into ApiController? -


i have class called query contains function calls data using sql query.

        public static userdetails[] binddatatable()     {         datatable dt = new datatable();         list<userdetails> details = new list<userdetails>();          using (sqlconnection con = new sqlconnection(configurationmanager.connectionstrings["###"].connectionstring))         {             using (sqlcommand cmd = new sqlcommand("select top 3 deal, [property], [event] [dbo].[database_cre_events]", con))             {                 con.open();                 sqldataadapter da = new sqldataadapter(cmd);                 da.fill(dt);                 foreach (datarow dtrow in dt.rows)                 {                     userdetails user = new userdetails();                     user.deal = dtrow["deal"].tostring();                     user.loanproperty = dtrow["property"].tostring();                     user.events = dtrow["event"].tostring();                     details.add(user);                 }             }         }         return details.toarray();     } 

i know how can pass query webapi controller? possible, not find examples online further guide me build.

public class testcontroller : apicontroller {      private cdwentities db = new cdwentities();      private query respository;      [httpget]     public httpresponsemessage getdata()     {        // not sure how pass method query class here?              } } 

many help.

first of why method in static?

public static userdetails[] binddatatable() 

so if static must consume this.

var result = query.binddatatable(); 

but if mistake must consume this, current implementation correct, have remove static modifier , call on respository instance.

[httpget] public httpresponsemessage getdata() {    var result = repository.binddatatable(); } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -