3 Replies - 821 Views - Last Post: 13 March 2017 - 05:02 AM

#1 Vegeta ZA  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 09-March 17

MVC List Not Working as it should

Posted 09 March 2017 - 06:50 AM

Hi Everyone,

So the issue that I am having is getting the correct db items to work in the search in the web page, for some reason it does not search all of the values from Vehicle_Make that exist in Vehicle_Details - Make_ID is the primary key of Vehicle_Make and it is a FK in Vehicle_Details.

What happens is, it shows all the items on the page in a list, but the search does not work when I search for any of those items.

[HttpPost]
public ActionResult Search(string Location)
{

           GoogleMapEntities GE = new GoogleMapEntities();

        ////SELECT Make_Name DATA FROM DB1
        var result = GE.Vehicle_Make.Where(x => x.Make_Name.StartsWith(Location)).ToList();
        var GetVeh = (from vd in db.Vehicle_Details
                      join vm in db.Vehicle_Make
                      on vd.Make_ID equals vm.Make_ID
                      join u in db.User
                      on vd.User_ID equals u.User_ID                        
                      select vd).ToList();

        //SELECT ALL ELEMENTS FROM Veh Make TABLE THAT EXISTS ON Veh Details TABLE BASED ON EXISTING ID's            
        var resultFinal = (from e in result
                           where (from m in GetVeh   
                                  select m.Make_ID).Contains(e.Make_ID)
                           select e
                          ).ToList();

        return Json(resultFinal, JsonRequestbehavior.AllowGet);

    }
}
}


Another weird thing that happens is, if I add the "!" in the following code, it does return the vehicle makes that do not exist in the vehicle details table but without the "!", it does not search for the values that do exist in both tables.

var resultFinal = (from e in result
where !(from m in GetVeh
select m.Make_ID).Contains(e.Make_ID)
select e
).ToList();


Thanks !

Is This A Good Question/Topic? 0
  • +

Replies To: MVC List Not Working as it should

#2 andrewsw  Icon User is offline

  • lashings of ginger beer
  • member icon

Reputation: 6340
  • View blog
  • Posts: 25,565
  • Joined: 12-December 12

Re: MVC List Not Working as it should

Posted 09 March 2017 - 10:50 AM

Question moved to ASP.NET MVC subforum.

Post some sample data and a description of what you are trying to achieve. (I doubt that it is necessary to construct three queries to obtain the data you need.)

Set a breakpoint and step through your code to confirm what each collection holds. There is a link to a debugging tutorial in my signature below.
Was This Post Helpful? 0
  • +
  • -

#3 Vegeta ZA  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 09-March 17

Re: MVC List Not Working as it should

Posted 09 March 2017 - 11:50 PM

Sample Data:
1. BMW exists in Vehicle_Make(Make_ID PK) and Vehicle_Details(Make_ID FK).
2. Vespa exists in Vehicle_Make but not in Vehicle_Details

If I search for BMW it does not work but if I search for Vespa or any vehicle that does not exist in the Vehicle_Details table, it will find those, but not the vehicles that exist in both tables.

Once I get the correct items that need to be searched for like BMW, it must match the Dealerships(Users table) and take the MapLat & MapLong from the "Users" table and then pin point them onto the map.

Vehicle_Details has (User_ID FK) which is the PK of the Users Table.

Basically, Vehicle_Details has Users and Vehicle_Make linked to it, while Users and Vehicle_Make do not have a link in them so therefore vehicle details is the link. Is this possible to make work for what I require?

This post has been edited by andrewsw: 10 March 2017 - 12:10 AM
Reason for edit:: Removed previous quote, just press REPLY

Was This Post Helpful? 0
  • +
  • -

#4 Vegeta ZA  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 09-March 17

Re: MVC List Not Working as it should

Posted 13 March 2017 - 05:02 AM

Anyone have an idea on how to fix this?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1