Quantcast
Channel: URF - Unit of Work & (extensible/generic) Repositories Framework
Viewing all articles
Browse latest Browse all 1539

Closed Unassigned: The entity type is not part of the model for the current context. [1196]

$
0
0
Hi.

I am trying to integrate this example in my work. But I run into a problem with my entities.

I get this when accessing my repository on an entity:

> System.InvalidOperationException: The entity type Estate is not part of the model for the current context.

In the Repository.cs:

```
public virtual void Insert(TEntity entity)
{
((IObjectState)entity).ObjectState = ObjectState.Added;
_dbSet.Attach(entity); // <-- The error occurs here
_context.SyncObjectState(entity);
}
```

This is my DbContext:

```
public partial class DimensionWebDbContext : DbContextBase
{
public DimensionWebDbContext() :
base("DimensionWebContext")
{
Database.SetInitializer<DimensionWebDbContext>(new CreateDatabaseIfNotExists<DimensionWebDbContext>());
Configuration.ProxyCreationEnabled = false;
}

public new IDbSet<T> Set<T>() where T : class
{
return base.Set<T>();
}

}
```

And the Entity:

```
public class Estate : EntityBase
{
public int Id { get; set; }
public string Name { get; set; }
public string Subject { get; set; }
public DateTime DateAdded { get; set; }
public Status Status { get; set; }
public decimal GrossArea { get; set; }
public decimal NetArea { get; set; }
public decimal CommenArea { get; set; }
public int Year { get; set; }
public int Rooms { get; set; }
public bool Balcony { get; set; }
public decimal Price { get; set; }
public decimal Payment { get; set; }

public virtual EstateAddress Address { get; set; }
public virtual EstateType Type { get; set; }
}


```

What causes this?

Thanks,
Jan

Viewing all articles
Browse latest Browse all 1539

Trending Articles