c# - groupBy query Error -


we trying return query in viewbag , en error of:

the key switch type of reading method , groupby , not comparable basic database provider .

this our controller:

public viewresult index(string sortorder, string searchstring, decimal searchprice = -1)         {             viewbag.namesortparm = string.isnullorempty(sortorder) ? "namedesc" : "";             viewbag.productsortparm = sortorder == "namep" ? "namepdesc" : "namep";             viewbag.companysortparm = sortorder == "names" ? "namesdesc" : "names";             var customers = s in db.customers                            select s;             if (!string.isnullorempty(searchstring))             {                 customers = customers.where(s => s.name.toupper().contains(searchstring.toupper())                                        || s.namep.toupper().contains(searchstring.toupper()));             }             if (!searchprice.equals(-1))             {                 var cust = s in db.products                            s.price < searchprice                            join sa in db.suppro on s.productid equals sa.productid                            join f in db.customers on sa.customerid equals f.customerid                            group s.price new                            {                                f.customerid,                                f.name,                                f.namep,                                f.names,                                f.phone,                                f.address,                                f.email,                                f.suppro                            } ncust                            select new customer { customerid = ncust.key.customerid, names = ncust.key.names, namep = ncust.key.namep, name = ncust.key.name, phone = ncust.key.phone, address = ncust.key.address, email = ncust.key.email, suppro = ncust.key.suppro };                 viewbag.cust = cust.tolist();             } 

this our view:

@model ienumerable<application_project.models.customer> @{     viewbag.title = "index";     var fromview = viewbag.cust ienumerable<application_project.models.customer>; }   <h2>index</h2>  <p>     @html.actionlink("create new", "create") </p>  @using (html.beginform()) {     <p>         price:  @html.textbox("searchprice")         customer name: @html.textbox("searchstring")           <input type="submit" value="search" /></p> } @if (fromview==null) { <table class="table">     <tr>         <th>             @html.actionlink("name", "index", new { sortorder = viewbag.namesortparm })         </th>         <th>             @html.actionlink("product", "index", new { sortorder = viewbag.productsortparm })         </th>         <th>             @html.actionlink("company", "index", new { sortorder = viewbag.companysortparm })         </th>         <th>             @html.displaynamefor(model => model.phone)         </th>         <th>             @html.displaynamefor(model => model.address)         </th>         <th>             @html.displaynamefor(model => model.email)         </th>         <th></th>     </tr>  @foreach (var item in model) {     <tr>         <td>             @html.displayfor(modelitem => item.name)            </td>         <td>             @html.displayfor(modelitem => item.namep)         </td>         <td>             @html.displayfor(modelitem => item.names)         </td>         <td>             @html.displayfor(modelitem => item.phone)         </td>         <td>             @html.displayfor(modelitem => item.address)         </td>         <td>             @html.displayfor(modelitem => item.email)         </td>         <td>             @html.actionlink("edit", "edit", new { id=item.customerid }) |             @html.actionlink("details", "details", new { id=item.customerid }) |             @html.actionlink("delete", "delete", new { id=item.customerid })         </td>     </tr> } </table> } else {    <table class="table">     <tr>         <th>             @html.actionlink("name", "index", new { sortorder = viewbag.namesortparm })         </th>         <th>             @html.actionlink("product", "index", new { sortorder = viewbag.productsortparm })         </th>         <th>             @html.actionlink("company", "index", new { sortorder = viewbag.companysortparm })         </th>         <th>             @html.displaynamefor(model => model.phone)         </th>         <th>             @html.displaynamefor(model => model.address)         </th>         <th>             @html.displaynamefor(model => model.email)         </th>         <th></th>     </tr>  @foreach (var item in fromview) {     <tr>         <td>             @html.displayfor(modelitem => item.name)            </td>         <td>             @html.displayfor(modelitem => item.namep)         </td>         <td>             @html.displayfor(modelitem => item.names)         </td>         <td>             @html.displayfor(modelitem => item.phone)         </td>         <td>             @html.displayfor(modelitem => item.address)         </td>         <td>             @html.displayfor(modelitem => item.email)         </td>         <td>             @html.actionlink("edit", "edit", new { id=item.customerid }) |             @html.actionlink("details", "details", new { id=item.customerid }) |             @html.actionlink("delete", "delete", new { id=item.customerid })         </td>     </tr> } </table>  } 

this our customer model:

public class customer {     [key]     public int customerid { get; set; }     public string names { get; set; }     public string namep { get; set; }     public string name { get; set; }     public string phone { get; set; }     public string address { get; set; }     public string email { get; set; }      public virtual icollection<suppro> suppro { get; set; } } 

try change part removing price

group s.price new group s new 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -