I follow the Pro ASP.net MVC 2 Framework book, which I found quite brilliant. But this is a real learning curve, and now I'm stuck.
In the book, you create something like below, which allows swapping.
public ViewResult List([DefaultValue(0)] string cityzip, [DefaultValue(1)] int page)
{
var roomsToShow = roomsRepository.Rooms.Where(x => x.CountryID == cityzip);
var viewModel = new RoomsListViewModel
{
Rooms = roomsToShow.Skip((page - 1) * PageSize).Take(PageSize).ToList(),
PagingInfo = new PagingInfo
{
CurrentPage = page,
ItemsPerPage = PageSize,
TotalItems = roomsToShow.Count()
}
};
return View(viewModel);
}
It seems to me that it was necessary to adapt this so that I can make a connection in the search
public ViewResult List([DefaultValue(0)] string cityzip, [DefaultValue(1)] int page)
{
var roomsToShow = roomsRepository.Rooms.Join(
roomCoordinatesRepository.RoomCoordinates,
room => room.RoomID,
roomCoordinate => roomCoordinate.RoomID,
(room, roomCoordinate) => new { RoomCoordinate = roomCoordinate, Room = room });
var viewModel = new RoomsListViewModel
{
Rooms = roomsToShow.Skip((page - 1) * PageSize).Take(PageSize).ToList(),
PagingInfo = new PagingInfo
{
CurrentPage = page,
ItemsPerPage = PageSize,
TotalItems = roomsToShow.Count()
}
};
return View(viewModel);
}
... but immediately I get an intellisense error message: Unable to implicitly convert type 'System.Collections.Generic.List<AnonymousType#1>'to 'System.Collections.Generic.IList<MeetingRoom.Domain.Entities.Room>'. Explicit conversion exists (are you skipping listing?)
I obviously donβt understand the code enough to understand whatβs wrong. I also feel a little deep inside with this lamda linq material
A room is a domain object that is defined as:
namespace MeetingRoom.Domain.Entities
{
[Table(Name = "Rooms")]
public class Room
{
[Column(IsPrimaryKey = true, IsDbGenerated = true, AutoSync = AutoSync.OnInsert)]
public int RoomID { get; set; }
[Column] public string Name { get; set; }
[Column] public string Description { get; set; }
[Column] public decimal Price { get; set; }
[Column] public string Category { get; set; }
[Column] public string Pcode { get; set; }
[Column] public int CountryID { get; set; }
public MeetingRooms.Domain.entities.RoomCoordinate RoomCoordinate { get; set; }
}
}
My Room. - , Room Room-?
- :
namespace MeetingRooms.Domain.entities
{
[Table(Name = "RoomCoordinate")]
public class RoomCoordinate
{
[Column(IsPrimaryKey = true, IsDbGenerated = true, AutoSync = AutoSync.OnInsert, Name = "ID")]
public int CoordID { get; set; }
[Column]
public int RoomID { get; set; }
[Column]
public string Coordinates { get; set; }
[Column]
public decimal Latitude { get; set; }
[Column]
public decimal Longitude { get; set; }
}
}
The RoomsListViewModel :
MeetingRoomsMVC.WebUI.Models
{ RoomsListViewModel { public IList RoomsWithCoordinates {get; ; } public PagingInfo PagingInfo {get; ; }
}
}