Crystal Report中的LinqToSql查询返回SystemNotSupportedException

时间:2019-06-08 15:48:19

标签: c# wpf linq-to-sql

我用来构建Crystal Report的TO-SQL`查询:

 private void Arrivages()
    {
        using(DataClasses1DataContext dc=new DataClasses1DataContext())
        {
            var datas = (from art in dc.FICHES_ARTICLES
                         join ent in dc.ENTREES_STOCKS on art.ART_CODE equals ent.ART_CODE
                         where art.ART_SITE == 7 && art.ART_CODE == "A34815E1"
                         select new
                         {
                             art.ART_CODE,
                             art.ART_LIBELLE1,
                             art.ART_LIBELLE2,
                             //art.ART_EAN13,
                             art.ART_SIGNEQ,
                             ent.ENTSTK_LOT,
                             ent.ENTSTK_PNET,
                             ent.ENTSTK_DTENTREE,
                             ent.ENTSTK_NBU,
                             ent.ENTSTK_DATE_DEM,
                             ent.ENTSTK_USER
                         }).ToList();

            string reportPath = @"O:\GT\GT9999 - Applications\GL-T\Dossiers GL-T\Reports\Rapport1.rpt";
            ReportDocument cr = new ReportDocument();
            cr.Load(reportPath);
            cr.SetDataSource(datas);
            Cr_Viewer.ViewerCore.ReportSource = cr;
        }
    }

但是当我运行该应用程序时,出现错误:

  

SystemNot SupportedException:包含System.Nullable <>的数据集。

英文信息

  

SystemNot SupportedException:数据集不支持System.Nullable <>

Error picture

我如何摆脱这个错误?谢谢您的帮助。

1 个答案:

答案 0 :(得分:0)

由于您写道:ENTSTK_DATE_DEM字段为空,请尝试替换空值。您还可以将其转换为字符串,然后执行以下操作:

var datas = (from art in dc.FICHES_ARTICLES
    join ent in dc.ENTREES_STOCKS on art.ART_CODE equals ent.ART_CODE
    where art.ART_SITE == 7 && art.ART_CODE == "A34815E1"
    select new { art, ent }).ToList()
    {
         art.ART_CODE,
         art.ART_LIBELLE1,
         art.ART_LIBELLE2,
         art.ART_SIGNEQ,
         ent.ENTSTK_LOT,
         ent.ENTSTK_PNET,
         ent.ENTSTK_DTENTREE,
         ent.ENTSTK_NBU,
         ENTSTK_DATE_DEM = ent.ENTSTK_DATE_DEM.HasValue ? ent.ENTSTK_DATE_DEM.Value.ToString() : string.Empty,
         ent.ENTSTK_USER
       };

别忘了将字段也转换为报表中的字符串。