2014-09-16 12 views
8

Sto utilizzando il servizio dati WCF (Odata) con .NET framework 4.5.1 e EF 6.1. Ho usato il primo approccio al codice per creare il modello EF. Quando ho fanno riferimento a questo modello EF (AddProjectModel.cs) a servizio WCF OData (WcfDataService1.svc), getta seguente errore:Servizio OData WCF e problema EF 6 - Impossibile esporre le entità utilizzando il servizio Odata

Errore:

Il server ha rilevato un errore durante l'elaborazione della richiesta. Il messaggio di eccezione è 'Su tipo di contesto dati' AddProjectModel ', c'è una proprietà IQueryable' Assets 'top il cui tipo di elemento non è un tipo di entità. Assicurarsi che la proprietà IQueryable sia di tipo entità o specificare l'attributo IgnoreProperties nel tipo di contesto dati per ignorare questa proprietà. '. Vedi i log del server per maggiori dettagli. L'analisi dello stack eccezione è:

a System.Data.Services.Providers.ReflectionServiceProvider.PopulateMetadata (ProviderMetadataCacheItem metadataCacheItem) a System.Data.Services.Providers.BaseServiceProvider.LoadMetadata (booleano skipServiceOperations) a System.Data.Services.DataService 1.CreateInternalProvider(Object dataSourceInstance) at System.Data.Services.DataService 1.CreateMetadataAndQueryProviders (IDataServiceMetadataProvider & metadataProviderInstance, IDataServiceQueryProvider & queryProviderInstance, Object & dataSourceInstance, booleano & isInternallyCreatedProvider) a System.Data.Services.DataService 1.CreateProvider() at System.Data.Services.DataService 1.HandleRequest() in System.Data.Services.DataService`1.ProcessRequestForMessage (stream messageBody) su SyncInvokeProcessRequestForMessage (Object, Object [], Object []) a System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke (istanza Object, Object [] input, Object [] & output) su System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin (MessageRpc & rpc) su System.ServiceModel.Dispatcher. ImmutableDispatchRuntime.ProcessMessage5 (MessageRpc & RPC) a System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41 (MessageRpc & RPC) a System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4 (MessageRpc & RPC) a System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31 (MessageRpc & rpc) a System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3 (MessageRpc & rpc) a System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2 (MessageRpc & RPC) a System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11 (MessageRpc & RPC) a System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1 (MessageRpc & RPC) a System.ServiceModel.Dispatcher.MessageRpc.Process (booleano isOperationContextSet)

Ecco il mio Data Service WCF: WcfDataService1.svc

namespace AddProjectService 
{ 
public class WcfDataService1 : DataService<AddProjectModel> 
{ 
    // This method is called only once to initialize service-wide policies. 
    public static void InitializeService(DataServiceConfiguration config) 
    { 
     // TODO: set rules to indicate which entity sets and service operations are visible, 
     updatable, etc. 
     // Examples: 
     config.SetEntitySetAccessRule("*", EntitySetRights.AllRead); 
     config.SetServiceOperationAccessRule("*", ServiceOperationRights.All); 
     config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3; 
    } 
} 
} 

My Code primo modello: AddProjectModel.cs classe

public partial class AddProjectModel : DbContext 
{ 
    public AddProjectModel() 
    : base("name=AddProjectModel") 
    { 
    } 

    public virtual DbSet<Asset> Assets { get; set; } 
    public virtual DbSet<Project> Projects { get; set; } 

    protected override void OnModelCreating(DbModelBuilder modelBuilder) 
    { 
    modelBuilder.Configurations.Add(new AssetMap()); 
    modelBuilder.Configurations.Add(new ProjectMap()); 
    }   
} 

public class AssetMap : EntityTypeConfiguration<Asset> 
{ 
    public AssetMap() 
    { 
    this.Property(a => a.AssetId).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);  
    this.HasMany(a => a.Projects).WithRequired(p => p.Asset).HasForeignKey(p => p.AssetId); 

    //table & column mappings 
    this.ToTable("TBLASSET"); 
    this.Property(a => a.AssetId).HasColumnName("ASSETID"); 
    this.Property(a => a.AssetLevelId).HasColumnName("ASSETLEVELID"); 
    this.Property(a => a.AssetNumber).HasColumnName("ASSETNUMBER"); 
    this.Property(a => a.Name).HasColumnName("NAME"); 
    this.Property(a => a.AssetTypeId).HasColumnName("ASSETTYPEID");  
} 
} 

public class ProjectMap : EntityTypeConfiguration<Project> 
{ 
    public ProjectMap() 
    { 
    this.Property(p => p.ProjectId).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity); 
    this.HasMany(p => p.SchedulePhases).WithRequired(sp => sp.Project).HasForeignKey(sp => 
    sp.ProjectId); 

    //table & column mappings 
    this.ToTable("TBLPROJECT"); 
    this.Property(p => p.ProjectId).HasColumnName("PROJECTID"); 
    this.Property(p => p.AssetId).HasColumnName("ASSETID"); 
    this.Property(p => p.CapitalCategoryId).HasColumnName("CAPITALCATEGORYID"); 
    this.Property(p => p.Comments).HasColumnName("COMMENTS"); 
    this.Property(p => p.DesignationId).HasColumnName("DESIGNATIONID"); 
    this.Property(p => p.DispositionId).HasColumnName("DISPOSITIONID"); 
    this.Property(p => p.FMSNumber).HasColumnName("FMSNUMBER"); 
    this.Property(p => p.FundingSourceId).HasColumnName("FUNDINGSOURCEID"); 
    this.Property(p => p.ImplementerId).HasColumnName("IMPLEMENTERID"); 
    this.Property(p => p.IsApproved).HasColumnName("ISAPPROVED"); 
    this.Property(p => p.IsDeferred).HasColumnName("ISDEFERRED"); 
    this.Property(p => p.IsLongTermLease).HasColumnName("ISLONGTERMLEASE"); 
    this.Property(p => p.IsRollover).HasColumnName("ISROLLOVER"); 
    this.Property(p => p.IsSidewalkBridge).HasColumnName("ISSIDEWALKBRIDGE"); 
    this.Property(p => p.JobDescription).HasColumnName("JOBDESCRIPTION"); 
    this.Property(p => p.JobType).HasColumnName("JOBTYPE"); 
    this.Property(p => p.OrganizationId).HasColumnName("ORGANIZATIONID"); 
    this.Property(p => p.ProgramCategoryId).HasColumnName("PROGRAMCATEGORYID"); 
    this.Property(p => p.DsfId).HasColumnName("DSFID"); 
    this.Property(p => p.StatusId).HasColumnName("STATUSID"); 

    this.Map<DomainObjectModel.ObjectModel.Project.ProjectCIP>(m => m.Requires("PROJECTTYPEID").HasValue(15)) 
     .Map<DomainObjectModel.ObjectModel.Project.ProjectCapacity>(m => m.Requires("PROJECTTYPEID").HasValue(2)); 
} 
} 

Asset:

public class Asset 
{ 
public Asset() 
{ 
    Projects = new HashSet<Project>();  
} 

[Key] 
public decimal AssetId { get; set; } 

[StringLength(20)] 
public string AssetNumber { get; set; } 

[StringLength(100)] 
public string Name { get; set; } 

public decimal? AssetLevelId { get; set; } 

public decimal? AssetTypeId { get; set; } 

public virtual ICollection<Project> Projects { get; set; }  
} 

classe Progetto:

public class Project 
{ 
public Project() 
{  
} 

[Key] 
public decimal ProjectId { get; set; } 

public decimal AssetId { get; set; } 

public decimal CapitalCategoryId { get; set; } 

//public decimal ProjectTypeId { get; set; } 

public decimal ProgramCategoryId { get; set; } 

[StringLength(1024)] 
public string Comments { get; set; } 

public decimal ImplementerId { get; set; } 

public decimal StatusId { get; set; } 

public decimal DsfId { get; set; } 

[StringLength(20)] 
public string FMSNumber { get; set; } 

[StringLength(1024)] 
public string JobDescription { get; set; } 

[StringLength(2)] 
public string JobType { get; set; } 

public decimal OrganizationId { get; set; } 

[Required][StringLength(1)] 
public string IsRollover { get; set; } 

[Required][StringLength(1)] 
public string IsDeferred { get; set; } 

[Required][StringLength(1)] 
public string IsApproved { get; set; } 

[StringLength(1)] 
public string IsSidewalkBridge { get; set; } 

public decimal FundingSourceId { get; set; } 

public decimal? DesignationId { get; set; } 

public decimal? DispositionId { get; set; } 

[Required][StringLength(1)] 
public string IsLongTermLease { get; set; } 

public virtual Asset Asset { get; set; } 
} 

non so come risolvere questo problema. Potresti dirmi per favore cosa mi manca qui?

Sto utilizzando il database di Oracle e abbiamo acquistato la licenza da devart per dotConnect per Oracle di recente.

Grazie,


Hi,

mi hanno risolto questo errore impostando [DataServiceKey] attributo con chiave primaria su ogni classi POCO. Si prega di fare riferimento a questo: http://blog.marcgravell.com/2008/12/astoria-and-linq-to-sql-getting-started.html.

Ora posso esporre entità attraverso il servizio odata ma quando provo ad accedere alla raccolta entità digitando l'URL getta seguente errore (ex .../WcfDataService1.svc/Assets.):

Errore:

<?xml version="1.0" encoding="utf-8" ?> 
<m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"> 
    <m:code /> 
    <m:message xml:lang="en-US">An error occurred while processing this request.</m:message> 
    <m:innererror> 
    <m:message>Operation could destabilize the runtime.</m:message> 
    <m:type>System.Security.VerificationException</m:type> 
    <m:stacktrace>at queryable_reader(Object) at System.Data.Services.Providers.ReflectionServiceProvider.GetQueryRootForResourceSet(ResourceSet container) at System.Data.Services.Providers.ReflectionDataServiceProvider.GetQueryRootForResourceSet(ResourceSet resourceSet) at System.Data.Services.Providers.DataServiceProviderWrapper.GetQueryRootForResourceSet(ResourceSetWrapper resourceSet) at System.Data.Services.RequestUriProcessor.ComposeExpressionForEntitySet(SegmentInfo segment, IDataService service, Boolean isLastSegment, Boolean checkRights) at System.Data.Services.RequestUriProcessor.ComposeExpressionForSegments(IList`1 segments, IDataService service, Boolean isCrossReferencingUri) at System.Data.Services.RequestUriProcessor.ProcessRequestUri(Uri absoluteRequestUri, IDataService service, Boolean internalQuery) at System.Data.Services.DataService`1.ProcessIncomingRequestUri() at System.Data.Services.DataService`1.HandleRequest()</m:stacktrace> 
    </m:innererror> 
</m:error> 

Come si risolve?

Grazie,

risposta

33

da usare WCF DataService con EF6, ci sono un po 'di lavoro in più per fare. Si prega di controllare i seguenti due post del blog per ingrandire:

Using WCF Data Services 5.6.0 with Entity Framework 6+

WCF Data Services Entity Framework Provider is updated with WCF Data Service 5.6.2

In generale, avrete bisogno dei seguenti due fasi:

  1. installare l'ultimo pacchetto di Nuget Microsoft.OData.EntityFrameworkProvider seguendo la guida su quella pagina;
  2. Sostituire DataService con EntityFrameworkDataService, dire nel tuo WcfDataService1.svc:

    public class WcfDataService1: EntityFrameworkDataService

+1

Grazie Karata. Ho ottenuto questo lavoro ora. – user659469

+2

Grazie. Perché oh, perché Microsoft non aggiorna i loro tutorial! – yonsk

+0

Mi ci sono voluti 6 ore per trovarlo. – Omzig

Problemi correlati