Having problems with the combining of two statements in a controller. Both statements work but cannot get them working as one element.
First statement is to show data for a user when his username matches the logged on usersname
This works fine.
public ViewResult Index()
{
var myrecords = db.Customers.Where(UserData => UserData.UserName.Equals
(User.Identity.Name)).ToList();
return View(myrecords);
}
Second statement is for connecting tables and showing the data. This works fine
var caradverts = db.CarAdverts.Include(c => c.BodyType).Include(c => c.Car).Include(c => c.Colour).Include(c => c.Customer).Include(c => c.EngineSize).Include(c => c.fuel).Include(c => c.SalesPlan).Include(c => c.Transmission).Include(c => c.year);
return View(caradverts.ToList());
Now the trouble is connecting both statements into one so it only shows the data for the user logged on.
Any advice welcome
How about this:
Do you really need all of these
Includestatements though? It looks like most of them refer to plain primitive properties and not related entities.Also because most likely in the first case you want data from a single user I would rewrite your query like this:
Then update your model/view accordingly to deal with a single
Customerrecord and not a collection.