0

Happy New Year everyone. Ok, i'm trying to create a 3 tier application and i have my references in the following order UI -> BLL -> DAL. The question is. The problem i'm having is with the Dbset. Because i have no reference to my models within my DAL, the dbset fails.

namespace MyApp.DAL
{
    public class MyAppDb : DbContext
    {
        public MyAppDb() : base("name=MyAppDBstring")
        { }

        public DbSet<SomeModel> SomeModels { get; set; }
    }
}

How do i get this to work if it cant find my SomeModel class in my BLL? Any help would be greatly appreciated.

dario
  • 5,149
  • 12
  • 28
  • 32
  • Where do your models sit? within DAL or BLL or within a different project? – Matt Jan 02 '15 at 10:08
  • Hi, sorry. I have three separate projects. The Web/UI, BLL and DAL. All my models are sat in my BLL. My BLL references my DAL so my DAL cant "see" my models. I'm pretty new to nTier applications so i'm finding this a bit of a challenge. This is all MVC pattern by the way. – Andy Poole Jan 02 '15 at 10:30

1 Answers1

0

In this case you would need to add a reference to your BLL project in your DAL project. Right click References>Add Reference and then the Solution tab tick your BLL project.

From this you will then be able to put a using statement on the top of the class above something along the lines of:

using MyApp.BLL;
Matt
  • 825
  • 2
  • 13
  • 25
  • I cant do that due to my BLL having a reference to my DAL. I'll get a circular dependency error. – Andy Poole Jan 02 '15 at 10:48
  • Ah sorry, I missed that in your question. You would be best looking at implementing an Interface between your BLL and your DAL. Without reinventing the wheel a very good explanation of this is : http://www.codeproject.com/Articles/616344/What-is-Circular-dependency-and-how-do-we-resolve – Matt Jan 02 '15 at 11:26
  • Thanks Matt. Looks like the way to go. :) – Andy Poole Jan 02 '15 at 14:07