2014-06-09 9 views
8

Sto eseguendo una procedura memorizzata aggiungendola nel modello esistente (edmx) mediante Aggiungi -> funzione Importa.Il lettore di dati non è compatibile con il modello specificato

Ho ricevuto il seguente errore.

Il lettore di dati non è compatibile con "dbModel.stored_procedure_Result" specificato. Un membro del tipo "UID" non ha una colonna corrispondente nel lettore di dati con lo stesso nome.

classe _Result del modello sia come segue

public partial class stored_procedure_Result 
{ 
    public int UID { get; set; } 
    public int SYSTEM_ID { get; set; } 
    public byte ACTIVE { get; set; } 
    public string LEVEL { get; set; } 
    public string SYSTEM_CODE { get; set; } 
    public string SYSTEM_NAME { get; set; } 
    public Nullable<int> SYSTEM_SUB_TYPE { get; set; } 
    public Nullable<int> PM_ID { get; set; } 
} 

Errore sulla linea di fondo di questa classe

using System; 
using System.Data.Entity; 
using System.Data.Entity.Infrastructure; 
using System.Data.Entity.Core.Objects; 
using Company.Product.Domain.Models; 

namespace Company.Product.Domain.Data 
{ 
    public partial class BusinessPartnerDataContext : DbContext 
    { 
     public BusinessPartnerDataContext() 
      : base("name=BusinessPartnerDataContext") 
     { 
     } 

     protected override void OnModelCreating(DbModelBuilder modelBuilder) 
     { 
      throw new UnintentionalCodeFirstException(); 
     } 


     public virtual ObjectResult<stored_procedure_Result> stored_procedure(Nullable<int> pCId, Nullable<int> pSystemId, Nullable<bool> pParameterShow, Nullable<bool> pRETActive, Nullable<bool> pAllLevels, Nullable<bool> pSystemSubTypeShow, Nullable<bool> pShowResultSet) 
     { 
      ((IObjectContextAdapter)this).ObjectContext.MetadataWorkspace.LoadFromAssembly(typeof(stored_procedure_Result).Assembly); 

      var pCIdParameter = pCId.HasValue ? 
       new ObjectParameter("pCId", pCId) : 
       new ObjectParameter("pCId", typeof(int)); 

      var pSystemIdParameter = pSystemId.HasValue ? 
       new ObjectParameter("pSystemId", pSystemId) : 
       new ObjectParameter("pSystemId", typeof(int)); 

      var pParameterShowParameter = pParameterShow.HasValue ? 
       new ObjectParameter("pParameterShow", pParameterShow) : 
       new ObjectParameter("pParameterShow", typeof(bool)); 

      var pRETActiveParameter = pRETActive.HasValue ? 
       new ObjectParameter("pRETActive", pRETActive) : 
       new ObjectParameter("pRETActive", typeof(bool)); 

      var pAllLevelsParameter = pAllLevels.HasValue ? 
       new ObjectParameter("pAllLevels", pAllLevels) : 
       new ObjectParameter("pAllLevels", typeof(bool)); 

      var pSystemSubTypeShowParameter = pSystemSubTypeShow.HasValue ? 
       new ObjectParameter("pSystemSubTypeShow", pSystemSubTypeShow) : 
       new ObjectParameter("pSystemSubTypeShow", typeof(bool)); 

      var pShowResultSetParameter = pShowResultSet.HasValue ? 
       new ObjectParameter("pShowResultSet", pShowResultSet) : 
       new ObjectParameter("pShowResultSet", typeof(bool)); 

      return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<stored_procedure_Result>("stored_procedure", pCIdParameter, pSystemIdParameter, pParameterShowParameter, pRETActiveParameter, pAllLevelsParameter, pSystemSubTypeShowParameter, pShowResultSetParameter); 
     } 
    } 
} 

procedura Sored è la seguente

ALTER PROCEDURE STORED_PROCEDURE 
AS 
DECLARE @SYSTEMS TABLE (UID int NOT NULL IDENTITY(1,1), 
         SYSTEM_ID int NOT NULL, 
         ACTIVE tinyint NOT NULL, 
         [LEVEL] char(2) NOT NULL, 
         SYSTEM_CODE char(2) NULL, 
         SYSTEM_NAME varchar(50) NULL, 
         pm_ID int NULL,SYSTEM_SUB_TYPE int NULL) 
INSERT INTO @SYSTEMS 
VALUES (1, 
     62, 
     1, 
     'LEVEL', 
     'CODE', 
     'NAME') 
SELECT UID, 
     SYSTEM_ID, 
     ACTIVE, 
     LEVEL, 
     SYSTEM_CODE, 
     SYSTEM_NAME 
FROM @SYSTEMS RETURN 0 

Esito della la procedura è

UID   SYSTEM_ID  ACTIVE  LEVEL  SYSTEM_CODE  SYSTEM_NAME 

1   62   1   LEVEL    CODE   NAME 

alcuni post suggerito di rimuovere l'istruzione RET dalla stored procedure, ho provato con commentando la dichiarazione RET nella stored procedure, come pure, ma non ha aiutato

alcuni post suggerisce di controllare i nomi delle colonne , Ho incoraggiato i nomi delle colonne nel tipo complesso, i nomi delle colonne esattamente corrispondenti

Alcuni post suggerivano che tutte le colonne presenti nella classe _Result dovessero essere RETATE dalla procedura, ma la classe _Result viene generata automaticamente, comunque ho provato a rimuovere anche le ultime due colonne, ma non è stato d'aiuto .. Inoltre l'errore dice colonna 'UID', ma a è presente nella procedura, risultato della procedura, classe _Result.

mi sento che l'errore è in alcuni riferimenti

using System; 
using System.Data.Entity; 
using System.Data.Entity.Infrastructure; 
using System.Data.Entity.Core.Objects; 
using Company.Product.Domain.Models; 

come quando il “Aggiornamento di modello dal database”, getta sempre errore come “non è possibile convertire System.Data.Object a System.Data.Entity .Core.Objects "

+0

uso UID come chiave primaria e specificare [Key] come attributo per la proprietà UID –

risposta

4

Per favore, cosa succede se segui questi passaggi?

1 - Aprire il fine Modello click Modello Browser

Open your Model end click Model Browser

2 - Aprire la cartella tipi complessi e cancellare il tuo stored_procedure_Result

Open Complex Types folder and delete your stored_procedure_Result

3 - Aprire la cartella stored procedure e fare doppio clic la tua procedura

Open Stored Procedure folder and double click your procedure

4 - Ottiene informazioni sulla colonna

5 - Crea un nuovo tipo complesso

Get Column Information and Create New Complex Type

+0

Questo dannato mi ha salvato la pancetta. – Kristopher

Problemi correlati