sjh37 / EntityFramework-Reverse-POCO-Code-First-Generator

EntityFramework Reverse POCO Code First Generator - Beautifully generated code that is fully customisable. This generator creates code as if you reverse engineered a database and lovingly created the code by hand. It is free to academics (you need a .edu or a .ac email address), not free for commercial use. Obtain your licence from
https://www.reversepoco.co.uk/
Other
704 stars 231 forks source link

Method 'Set' in type ...does not have an implementation #330

Open DBCTech opened 7 years ago

DBCTech commented 7 years ago

Hi,

I'm generating the entities using your POCO Generator in VS2013. It generates everything fine but when I access the DBContext object, it throws this error (see below). Please let me know if there is a config change I've missed or is this a bug in this system?

Thanks DBCTech

Method 'Set' in type 'TestPOCO1.MyDbContext' from assembly 'TestPOCO1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.TypeLoadException: Method 'Set' in type 'TestPOCO1.MyDbContext' from assembly 'TestPOCO1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.

sjh37 commented 7 years ago

Hi. Set is not yet implemented in the fake db context.

The code produces this for the fake db context:

public System.Data.Entity.DbSet Set(System.Type entityType)
{
    throw new System.NotImplementedException();
}
public System.Data.Entity.DbSet<TEntity> Set<TEntity>() where TEntity : class
{
    throw new System.NotImplementedException();
}

There is no implementation in the main db context as this is handled by the base class System.Data.Entity.DbContext.

For now you will have to add that function yourself to the fake db context. Once working, can you please show me the code here and I will add it the project and give you the credit. Sorry, and thanks.

DBCTech commented 7 years ago

Hi Simon,

Many thanks for a prompt reply. I've managed to get it working after your pointers. It turns out the FakeDBSet template is not creating those two methods for the context of the Database in question. I manually copied the two methods you have mentioned into my own DB's context class and it seems to have done the trick. So in my above scenario in MyDbContext class I added the following:

public System.Data.Entity.DbSet Set(System.Type entityType)
{
    throw new System.NotImplementedException();
}
public System.Data.Entity.DbSet<TEntity> Set<TEntity>() where TEntity : class
{
    throw new System.NotImplementedException();
}

For implementation I would use the following code:


public DbSet Set(Type entityType)
{
    Check.NotNull<Type>(entityType, "entityType");
    return (DbSet)this.InternalContext.Set(entityType);
}

public DbSet<TEntity> Set<TEntity>() where TEntity : class
{
    return (DbSet<TEntity>)this.InternalContext.Set<TEntity>();
}

Hope this helps, thanks for replying.

Murtie

kublaikhan1 commented 6 years ago

Isn't InternalContext Inaccessible due to protection level ? @DBCTech

Wouter8 commented 5 years ago

I encountered the same error when referencing a new project which contains the generated classes by this project. The existing project was an old project which already had a reference to EntityFramework. Updating this reference through NuGet solved the issue for me. Hope this helps someone in the future, since the error message isn't that helpful!