I am trying to combine the data from two repositories in MVC4. I am using a join statement in my Action function to gather information from two tables. I am passing this this data onto my view. I am a little confused to how to correctly combine the data from the two repositories. Some help would be appreciated. THANKS!

In controller:

     public IOwnerRepository OwnerDB;
     public IDwellingRepository DwellingDB;
     public OwnerController() : this(new OwnerRepository(), new DwellingRepository()) {}
     public OwnerController(IOwnerRepository oRepository, IDwellingRepository dRepository)
         OwnerDB    = oRepository;
         DwellingDB = dRepository;


public ActionResult Account(int id, int? activelink)
    // Link values
    // Account         = 0
    // Listings        = 1
    // Profile         = 2
    // Create Property = 3

    // Check for a value
    // If no value set to zero
    if (!activelink.HasValue)
        activelink = 0;

    // Fucking hackers
    if (activelink > 3)
        activelink = 0;

    ViewBag.ActiveLink = activelink.ToString();
    switch (activelink)
        case 0:
            ViewBag.Title = "Account Details";
        case 1:
            ViewBag.Title = "Listings";
        case 2:
            ViewBag.Title = "Profile";
        case 3:
            ViewBag.Title = "Create Property";
    var oOwner = OwnerDB.FindOne(GetUserId(), id);
    if (oOwner == null)
    return new FileNotFoundResult { Message = "No Account found for id " + id.ToString() };
    return View(oOwner);

Owner Repository:

 public Owner FindOne(string UserId, int id)
      var dwelling = (from o in db.Owner 
                    join d in db.Dwelling on o.ID equals d.Owner_ID into ps
                    from k in ps.DefaultIfEmpty()
                    select o );
      var oOwner = (from p in dwelling
                    where p.ID == id
                    select p);

      return oOwner.FirstOrDefault();

You will probably need more specific explanation about how exactly you want the repositories combined and what the code is or isn't doing.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.