web.config settings-
    <add name="MySqlConnection" connectionString="Server=;Port=3306;Database=grocery_db; User ID=root; Password=*****;" providerName="MySql.Data.MySqlClient" />   

      <remove invariant="MySql.Data.MySqlClient" />
      <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />

Controller code-

public ActionResult Summary()
    //string connectionString
    GrocerySummaryViewModel viewModel = new GrocerySummaryViewModel();
    List<GroceryWiseContactQuantity> groceryContactList = new List<GroceryWiseContactQuantity>();
        var db = new PetaPoco.Database("MySqlConnection");
        groceryContactList = db.Query<GroceryWiseContactQuantity>("SELECT grocery AS GroceryName, count(id) AS Quantity FROM contacts group by grocery order by count(id) desc").ToList();
        viewModel.GroceryWiseContactList = groceryContactList;
    catch (Exception Ex)
    return View("GrocerySummary", viewModel); 

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s