Is it possible to return a complex type from a WCF data service that is made of collections of entity types ?
for example :
//the complex type to return
class Entities
{
ICollection<Contract> Contracts;
...
}
//configuration
public partial class MyContext: DbContext
{
public MyContext()
: base("name=DBEntities")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.ComplexType<Entities>();
modelBuilder.Entity<Contract>().HasKey(c=>c.Id);
...
}
...
}
//the WCF Data Service
public class PricingDataService : DataService<ObjectContext>, IDisposable
{
[WebGet]
public Entities GetEntities()
{
return new Entities();
}
}
When I try the above configuration, I get an exception :
" The exception message is 'One or more validation errors
were detected during model generation: System.Data.Edm.EdmEntityType: Name:
Each type name in a schema must be unique. Type name 'Contract' was already
defined."
No this is not possible because if you define this, it means that complex type has navigation property to contracts. This is not allowed in whole entity framework. The error probably comes from some infering where Contract
is already defined as entity but complext type is trying to map it as something else - but this is just guess.