开发者

How to return Complex types from a WCF Data Service?

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
 {
    ICollectio开发者_C百科n<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.


For some reason the snippet you posted is hard to read for me. However, I can tell you that I have sent via WCF types like those. I usually don't use ICollection<> to declare my lists, I tend to use List<> instead and have never had much of a problem receiving the information on the client.

Maybe it's a problem on how you're defining the class on your data contract.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜