Generated DbContext vs Generated ObjectContext

Posts   
 
    
Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 19-May-2011 20:19:48   

just found this link... http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=19582&HighLight=1, revising questions...

using LLBLGen 3.1 the EF4 templates and targeting .NET 4 using options for Proxy friendly POCOs.

Question 1 -> Why would I use a generated ObjectContext vs. a generated DbContext?

When we generate the code from llblgen end up with an llblgen generated edmx file and a XXXDataContext. The XXXDataContext is a subclass of ObjectContext and the generated object context has accessors for getting ObjectSet<T>.

Now, when I point vs.net at the generated edmx file I can generate a DbContext using the EF4.1 tools.

The generated DbContext gives me access to my entities via DbSet which is a bit different from ObjectSet.

Question 2 -> is there an option to generate DbContext via the llblgen ide that I missed?

Question 3 -> if there is not a option today, when will there be one?

Question 4 -> what are the other llblgen users doing with EF4.1?

Prior to EF 4.1 I was hand rolling my own DataRepository<T> : IRepository<T> and injecting my llblgen generated ObjectContext into concrete data repositories. i.e.


class UserRepository : DataRepository<User>, IUserRepository{
  public bool DeleteUser(UserViewModel user){
    Delete(it => it.UserId == user.UserId);
    if (SaveChanges() > 0) 
      return true;
    else 
      return false;
  }
}

in the code above, Delete and SaveChanges are provided by DataRepository and the contract for boolDeleteUser is defined in IUserRepository.

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 19-May-2011 22:27:36   

The DBContext is new to EF4.1, which I don't think we have yet updated our templates to support. I'll check when this is planned for.

Matt

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 20-May-2011 10:57:04   

Devildog74 wrote:

just found this link... http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=19582&HighLight=1, revising questions...

using LLBLGen 3.1 the EF4 templates and targeting .NET 4 using options for Proxy friendly POCOs.

Question 1 -> Why would I use a generated ObjectContext vs. a generated DbContext?

We don't support Code first yet, and EF v4.1 is a wrapper around EF v4 with code first, nothing more.

When we generate the code from llblgen end up with an llblgen generated edmx file and a XXXDataContext. The XXXDataContext is a subclass of ObjectContext and the generated object context has accessors for getting ObjectSet<T>.

Now, when I point vs.net at the generated edmx file I can generate a DbContext using the EF4.1 tools.

The generated DbContext gives me access to my entities via DbSet which is a bit different from ObjectSet.

Yes, but there's no real difference. DbContext derives from ObjectContext as well, and is mainly used for code-first and is limited in featureset compared to the generated ObjectContext derived class. I'd use our code over DbContext any day, as you're not using code first (because you're using our designer)

Question 2 -> is there an option to generate DbContext via the llblgen ide that I missed? Question 3 -> if there is not a option today, when will there be one?

It's not there yet, as we don't support code first yet. it will come in the fall with v3.5

Question 4 -> what are the other llblgen users doing with EF4.1?

You can simply use EF v4.1 with our generated code, you just don't have the DbContext, but you do have the v4.1 runtime which has a couple of performance enhancements you benefit from. The only thing you don't have with our code is code first. As code first is targeted towards creating your model in code, we don't see it as a must-have today, as code first doesn't need a designer anyway. We will support it though, in a scaffolding fashion, similar to fluent NHibernate support: you can generate the mapping definitions + classes or just the mappings.

Frans Bouma | Lead developer LLBLGen Pro