dimanche 17 janvier 2016

How to join two model and display them in view in mvc 3.0 EF 5

I have two tables which have primary and foriegn key concept. I want to get the combined data on behalf of those keys. i don't know how to bind both the table into single model and display it into view.


public class TVSerialModel
    public Int32 Serial_ID { get; set; } // primary key
    public string Serial_Name { get; set; }                 
    public int? Release_Year { get; set; }           

public class TVSerialEpisodeModel
    public Int64 Video_ID { get; set; } 
    public Int32 Serial_ID { get; set; }// foriegn key
    public string Episode_Name { get; set; }
    public string Description { get; set; }        
    public DateTime Uploaded_Time { get; set; }

public class TVSerial_Episode_VM
    public IEnumerable<TVSerialEpisodeModel> tvserialEpisode { get; set; }
    public IEnumerable<TVSerialModel> Tvserial { get; set; }


public ActionResult NewEpisodeReleased()
    cDBContext tvContext = new cDBContext();

    TVSerial_Episode_VM tves=new TVSerial_Episode_VM(); 
    tves= tvContext.dbTvSerialEpisodes.
    Join(tvContext.dbTvSerials, p => p.Serial_ID, r => r.Serial_ID,(p, r) => new { p, r }).
Select(o => new TVSerial_Episode_VM
            { ****what should i write here to get all columns from both table**** }).
    return View(tves);

Expected Result

enter image description here

Aucun commentaire:

Enregistrer un commentaire