I have created a SQL Server view which performs some reasonably complex logic on other tables/entities in my model and which exposes a series of columns. All but one of these columns are simple types (bigints, nvarchars etc) but one is a complex entity within my model.
I have created an entity which maps to this view as follows:
public class NetworkSuppliersByClient : Entity, IKeyed<long>
{
public long NetworkSuppliersByClientId { get; set; }
public long NetworkId { get; set; }
public String NetworkName { get; set; }
public long OwningClientId { get; set; }
public long ClientId { get; set; }
public virtual Supplier Supplier { get; set; }
public bool PublicEntry { get; set; }
public long GetKey ()
{
return NetworkSuppliersByClientId;
}
}
As you can see, the Supplier entry maps to an existing entity within the model, itself being a complex type with other contained entities (aka tables).
The issue that I have is that when I try to read from the view I get the error "The entity type NetworkSuppliersByClient is not part of the model for the current context.".
However, when I try to register the entity with the context as a DbSet I get the error "There is already an object named 'NetworkSuppliersByClients' in the database." as it tries to create a table with the same name as the already existing view.
Is there any way around this, for example to inhibit EF from trying to create the table at startup, or is there a better way to read from a view?