0

I have the following code:

ViewData.Model = from m in dataModel.Items
                             where m.Loaned == cust.MembershipID
                                   &&
                                   m.MediaItem1.Type != null

                             select new Temp
                                        {
                                           Rating = m.Library.ItemRating.Rating,
                                           Title = m.MediaItem1.Title
                                         };

and

public class Temp
        {
            public string Title { get; set; }
            public int Rating { get; set; }
        }

I create a view using Temp as being the strong type. This works well and displays all the titles and ratings as it should.

What I want to achieve now is the following: I have another type of Item which I want to query also, the query will look very similar to the one above, it will also return titles and ratings, but it is still classed as a different category of 'item'. How can I implement this so it will send both queries through to the View - if that makes sense?

Thanks.

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670

1 Answers1

0

It the different type of Item is really different entity set in EF model and it is not inherited from Item you can simply use union:

ViewData.Model = (from m in dataModel.Items
              where m.Loaned == cust.MembershipID &&
                               m.MediaItem1.Type != null
              select new Temp
                  {
                      Rating = m.Library.ItemRating.Rating,
                      Title = m.MediaItem1.Title
                  })
             .Contact(
              from i in dataModel.DifferentItems
              where ...
              select new Temp
                  {
                      ...
                  });

But if you have inheritance modeled in your database (as requested in your other question) you can still query Item and you will get information about all derived entities.

Community
  • 1
  • 1
Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
  • This works in the respect that I can get all the items now in one Viewdata, however I cannot tell the difference from which may be a Movie for example, or which is a Game (Instead I have a list of titles and ratings) how could I make the two different types identifiable? Thanks. –  Mar 26 '11 at 16:08
  • In such case you must add specil property to Temp and fill it based on type of loaded entity. – Ladislav Mrnka Mar 26 '11 at 17:20