Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# &引用;InvalidCastException指定的强制转换无效;在ToList()中_C#_Oracle_Entity Framework - Fatal编程技术网

C# &引用;InvalidCastException指定的强制转换无效;在ToList()中

C# &引用;InvalidCastException指定的强制转换无效;在ToList()中,c#,oracle,entity-framework,C#,Oracle,Entity Framework,我在一个MVC4C应用程序中 其中我显示了一个oracle表的记录,但是当我执行它时抛出了这个异常, 我从来没有遇到过比这次更严重的问题 这是我的密码: public ActionResult Index() { Entities db = new Entities(); IList<MVC_PCMonitoring_Dash.TB_OP_PC_MONITORING_V4> PCList = new List<MVC_PCMoni

我在一个MVC4C应用程序中 其中我显示了一个oracle表的记录,但是当我执行它时抛出了这个异常, 我从来没有遇到过比这次更严重的问题

这是我的密码:

    public ActionResult Index()
    {
        Entities db = new Entities();
        IList<MVC_PCMonitoring_Dash.TB_OP_PC_MONITORING_V4> PCList = new List<MVC_PCMonitoring_Dash.TB_OP_PC_MONITORING_V4>();
        var query = from qrs in db.TB_OP_PC_MONITORING_V4 select qrs;
        var listdata = query.ToList();  // <-- This is where the exception occurs "Specified cast is not valid": 

        foreach (var pcdata in listdata)
        {
            PCList.Add(new TB_OP_PC_MONITORING_V4()
            {
                IDPC = pcdata.IDPC,
                LINE_CODE = pcdata.LINE_CODE,
                PROCESS_NAME = pcdata.PROCESS_NAME,
                PING_STATUS = pcdata.PING_STATUS,
                SFC_STATUS = pcdata.SFC_STATUS,
                FL_STATUS = pcdata.FL_STATUS,
                RAS_STATUS = pcdata.RAS_STATUS,
                PC_UTC = pcdata.PC_UTC,
                PC_PROCESSOR_STATUS = pcdata.PC_PROCESSOR_STATUS,
                PC_RAM_STATUS = pcdata.PC_RAM_STATUS,
                PC_VERSION = pcdata.PC_VERSION,
                IPADDRESS = pcdata.IPADDRESS,
            });
        }
        return View(PCList);
    }
问题是:

EDIT2:

EntityFramework表TB\u OP\u PC\u MONITORING\u V4创建模型时生成。edmx

  namespace MVC_PCMonitoring_Dash
    {
        using System;
        using System.Collections.Generic;
        
        public partial class TB_OP_PC_MONITORING_V4
        {
            public decimal IDPC { get; set; }
            public string IPADDRESS { get; set; }
            public string PC_NAME { get; set; }
            public string PC_MAC { get; set; }
            public string PC_MODEL { get; set; }
            public string PC_SN { get; set; }
            public string PC_MFG { get; set; }
            public string PC_PROCESSOR { get; set; }
            public string PC_SPEED { get; set; }
            public string PC_RAM { get; set; }
            public string PC_CORE { get; set; }
            public string PC_USERNAME { get; set; }
            public string PC_VERSION { get; set; }
            public string PC_SERVICEPACK { get; set; }
            public string PC_ARCH { get; set; }
            public string PC_SERIALKEY { get; set; }
            public string PC_REG_USER { get; set; }
            public string PC_INSTALL_DATE { get; set; }
            public string LINE_CODE { get; set; }
            public string PROCESS_NAME { get; set; }
            public Nullable<decimal> ORDER_RATE { get; set; }
            public string MACHINE_TYPE { get; set; }
            public Nullable<System.DateTime> CREATE_DATE { get; set; }
            public string SFC_STATUS { get; set; }
            public Nullable<System.DateTime> UPDATE_SFC { get; set; }
            public Nullable<System.DateTime> SYS_UPDATE_SFC { get; set; }
            public Nullable<decimal> TIME_OUT_SFC { get; set; }
            public string FL_STATUS { get; set; }
            public Nullable<System.DateTime> UPDATE_FL { get; set; }
            public Nullable<System.DateTime> SYS_UPDATE_FL { get; set; }
            public Nullable<decimal> TIME_OUT_FL { get; set; }
            public string PING_STATUS { get; set; }
            public Nullable<System.DateTime> UPDATE_PING { get; set; }
            public Nullable<System.DateTime> SYS_UPDATE_PING { get; set; }
            public Nullable<decimal> TIME_OUT_PING { get; set; }
            public string RAWS { get; set; }
            public string PC_PROCESSOR_STATUS { get; set; }
            public string PC_RAM_STATUS { get; set; }
            public string PC_UTC { get; set; }
            public string RAS_STATUS { get; set; }
            public Nullable<System.DateTime> UPDATE_RAS { get; set; }
            public Nullable<System.DateTime> SYS_UPDATE_RAS { get; set; }
            public Nullable<decimal> TIME_OUT_RAS { get; set; }
        }
    }
namespace MVC\u PCMonitoring\u Dash
{
使用制度;
使用System.Collections.Generic;
公共部分类TB_OP_PC_监控_V4
{
公共十进制IDPC{get;set;}
公共字符串IPADDRESS{get;set;}
公共字符串PC_NAME{get;set;}
公共字符串PC_MAC{get;set;}
公共字符串PC_模型{get;set;}
公共字符串PC_SN{get;set;}
公共字符串PC_-MFG{get;set;}
公共字符串PC_处理器{get;set;}
公共字符串PC_速度{get;set;}
公共字符串PC_RAM{get;set;}
公共字符串PC_核心{get;set;}
公共字符串PC_用户名{get;set;}
公共字符串PC_版本{get;set;}
公共字符串PC_SERVICEPACK{get;set;}
公共字符串PC_ARCH{get;set;}
公共字符串PC_SERIALKEY{get;set;}
公共字符串PC_REG_USER{get;set;}
公共字符串PC_安装_日期{get;set;}
公共字符串行_代码{get;set;}
公共字符串进程名称{get;set;}
公共可为空的顺序\u比率{get;set;}
公共字符串计算机\u类型{get;set;}
公共可空的CREATE_DATE{get;set;}
公共字符串SFC_状态{get;set;}
公共可空更新\u SFC{get;set;}
公共可为空的SYS\u UPDATE\u SFC{get;set;}
公共可为空的时间\u OUT\u SFC{get;set;}
公共字符串FLU状态{get;set;}
公共可空更新{get;set;}
公共可为空的系统更新{get;set;}
公共可为空的时间\u OUT\u FL{get;set;}
公共字符串PING_状态{get;set;}
公共可空更新{get;set;}
公共可为空的系统更新{get;set;}
公共可为空的超时{get;set;}
公共字符串RAWS{get;set;}
公共字符串PC_处理器_状态{get;set;}
公共字符串PC_RAM_STATUS{get;set;}
公共字符串PC_UTC{get;set;}
公共字符串rasu STATUS{get;set;}
公共可空更新{get;set;}
公共可为空的系统更新{get;set;}
公共可为空的时间\u OUT\u RAS{get;set;}
}
}
模型1.上下文

namespace MVC_PCMonitoring_Dash
{
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Infrastructure;
    
    public partial class Entities : DbContext
    {
        public Entities()
            : base("name=Entities")
        {
        }
    
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            throw new UnintentionalCodeFirstException();
        }
    
        public DbSet<TB_TEST> TB_TEST { get; set; }
        public DbSet<TB_OP_PC_MONITORING_V4> TB_OP_PC_MONITORING_V4 { get; set; }
    }
}
namespace MVC\u PCMonitoring\u Dash
{
使用制度;
使用System.Data.Entity;
使用System.Data.Entity.Infrastructure;
公共部分类实体:DbContext
{
公共实体()
:base(“名称=实体”)
{
}
模型创建时受保护的覆盖无效(DbModelBuilder modelBuilder)
{
抛出新代码FirstException();
}
公共数据库集TB_测试{get;set;}
公共数据库集TB_OP_PC_MONITORING_V4{get;set;}
}
}
EDIT3:

基于结果更新字段的Oracle过程

create or replace procedure SP_DASHBOARD_PINGSTATUS is
begin
  declare

  BEGIN
       Update rsmes.tb_op_pc_monitoring_v4 t
        set t.sys_update_ping = sysdate,
            t.sys_update_sfc = sysdate,
            t.sys_update_fl = sysdate,
            t.sys_update_ras = sysdate,
            t.pc_utc = (select 'UTC' || substr(current_timestamp, '30','6')timezonenumber from dual);
   for c in (select ipaddress,((SYS_UPDATE_PING - UPDATE_PING)*60*60*24) as PING_RESULT from TB_OP_PC_MONITORING_V4)
     loop
        Update rsmes.tb_op_pc_monitoring_v4 tg
         set tg.ping_status =
                case
                  when (SYSDATE - tg.update_ping) * 60 * 60 * 24 <= 5 then 'OK'
                  else 'NG'
                end,
                tg.time_out_ping = (SYSDATE - tg.update_ping) * 60 * 60 * 24;
       end loop;
   for d in (select ipaddress,((SYS_UPDATE_SFC - UPDATE_SFC)*60*60*24) as SFC_RESULT from TB_OP_PC_MONITORING_V4)
     loop
        Update rsmes.tb_op_pc_monitoring_v4 tg2
         set tg2.sfc_status =
                case
                  when (SYSDATE - tg2.update_sfc) * 60 * 60 * 24 <= 5 then 'OK'
                  else 'NG'
                end,
                tg2.time_out_sfc = (SYSDATE - tg2.update_sfc) * 60 * 60 * 24;
       end loop;
   for e in (select ipaddress,((SYS_UPDATE_FL - UPDATE_FL)*60*60*24) as FL_RESULT from TB_OP_PC_MONITORING_V4)
     loop
        Update rsmes.tb_op_pc_monitoring_v4 tg3
         set tg3.fl_status =
                case
                  when (SYSDATE - tg3.update_fl) * 60 * 60 * 24 <= 5 then 'OK'
                  else 'NG'
                end,
                tg3.time_out_fl = (SYSDATE - tg3.update_fl) * 60 * 60 * 24;
       end loop;
   for f in (select ipaddress,((SYS_UPDATE_RAS - UPDATE_RAS)*60*60*24) as RAS_RESULT from TB_OP_PC_MONITORING_V4)
     loop
        Update rsmes.tb_op_pc_monitoring_v4 tg3
         set tg3.ras_status =
                case
                  when (SYSDATE - tg3.update_ras) * 60 * 60 * 24 <= 5 then 'OK'
                  else 'NG'
                end,
                tg3.time_out_ras = (SYSDATE - tg3.update_ras) * 60 * 60 * 24;
       end loop;
        commit;
  END;
end SP_DASHBOARD_PINGSTATUS;
创建或更换程序SP_仪表板_ping状态为
开始
声明
开始
更新rsmes.tb_op_pc_monitoring_v4 t
设置t.sys\u update\u ping=sysdate,
t、 sys\u update\u sfc=sysdate,
t、 sys\u update\u fl=sysdate,
t、 sys\u update\u ras=sysdate,
t、 pc_utc=(从dual中选择'utc'| | substr(当前时间戳,'30','6')TimeZoneumber);
对于c in(选择ipaddress,((系统更新\u PING-更新\u PING)*60*60*24)作为TB\u OP\u PC\u监控\u V4的PING结果)
环
更新rsmes.tb_op_pc_monitoring_v4 tg
设置tg.ping_状态=
案例

何时(SYSDATE-tg.update\u ping)*60*60*24这是什么ORM?实体框架?无论如何,我猜您模型中的某个类型与数据库中相应列的数据类型不匹配,因此当您实际实现查询时,它无法成功转换该类型。是的,我使用EF,我不明白为什么异常会抛出错误,因为我的所有表都有一个主键-从不为null-类型号。qrs的类型是什么?@BlackSD,但其他列中的一列可能是问题所在。大多数代码
Entities db=new Entities();IList PCList=新列表();var query=从db.TB_OP_PC_MONITORING_V4中的qrs选择qrs;var listdata=query.ToList();foreach(listdata中的var pcdata)
是冗余的。基本上是
Entities db=newentities();返回视图(db.TB\u OP\u PC\u MONITORING\u V4.ToList())
,并不是说它能解决问题。显示实体类和映射。使用DTO,而不是将DB实体放入视图中
create or replace procedure SP_DASHBOARD_PINGSTATUS is
begin
  declare

  BEGIN
       Update rsmes.tb_op_pc_monitoring_v4 t
        set t.sys_update_ping = sysdate,
            t.sys_update_sfc = sysdate,
            t.sys_update_fl = sysdate,
            t.sys_update_ras = sysdate,
            t.pc_utc = (select 'UTC' || substr(current_timestamp, '30','6')timezonenumber from dual);
   for c in (select ipaddress,((SYS_UPDATE_PING - UPDATE_PING)*60*60*24) as PING_RESULT from TB_OP_PC_MONITORING_V4)
     loop
        Update rsmes.tb_op_pc_monitoring_v4 tg
         set tg.ping_status =
                case
                  when (SYSDATE - tg.update_ping) * 60 * 60 * 24 <= 5 then 'OK'
                  else 'NG'
                end,
                tg.time_out_ping = (SYSDATE - tg.update_ping) * 60 * 60 * 24;
       end loop;
   for d in (select ipaddress,((SYS_UPDATE_SFC - UPDATE_SFC)*60*60*24) as SFC_RESULT from TB_OP_PC_MONITORING_V4)
     loop
        Update rsmes.tb_op_pc_monitoring_v4 tg2
         set tg2.sfc_status =
                case
                  when (SYSDATE - tg2.update_sfc) * 60 * 60 * 24 <= 5 then 'OK'
                  else 'NG'
                end,
                tg2.time_out_sfc = (SYSDATE - tg2.update_sfc) * 60 * 60 * 24;
       end loop;
   for e in (select ipaddress,((SYS_UPDATE_FL - UPDATE_FL)*60*60*24) as FL_RESULT from TB_OP_PC_MONITORING_V4)
     loop
        Update rsmes.tb_op_pc_monitoring_v4 tg3
         set tg3.fl_status =
                case
                  when (SYSDATE - tg3.update_fl) * 60 * 60 * 24 <= 5 then 'OK'
                  else 'NG'
                end,
                tg3.time_out_fl = (SYSDATE - tg3.update_fl) * 60 * 60 * 24;
       end loop;
   for f in (select ipaddress,((SYS_UPDATE_RAS - UPDATE_RAS)*60*60*24) as RAS_RESULT from TB_OP_PC_MONITORING_V4)
     loop
        Update rsmes.tb_op_pc_monitoring_v4 tg3
         set tg3.ras_status =
                case
                  when (SYSDATE - tg3.update_ras) * 60 * 60 * 24 <= 5 then 'OK'
                  else 'NG'
                end,
                tg3.time_out_ras = (SYSDATE - tg3.update_ras) * 60 * 60 * 24;
       end loop;
        commit;
  END;
end SP_DASHBOARD_PINGSTATUS;