.NET LINQ 实现跨数据库数据的整合

      如果要在不同的数据库之间,要把数据整合到一起,或者对数据进行统计分析的话,实现起来比较麻烦。

      一般情况下我们第一时间想到的方法是通过前置机实现,在前置机上安装一个数据库和同步数据程序,定时的把数据同步到数据库中,这样的实现方法虽然是可行的,但是成本增加了,而且数据不实时。

      

查询表达式LINQ简介:     https://kb.cnblogs.com/page/42597/1/

 利用LINQ获取不同数据库例子如下:

        // 获取病历时间轴数据集
        public DataTable GetEmrTimeLineDtByMrn(string mrn)
        {
            DataTable dt = null;
            //获取银江电子病历
            string esql = "select * from his_cpr_pr where mrn=@mrn";
            DataTable edt = MsSqlHelper.ExecuteDataTable(ConnStr, esql, new SqlParameter("@mrn", mrn));

            //获取联众电子病历
            string esql1 = "select * from his_cpr_pr where mrn=:mrn";
            DataTable edt1 = OracleHelper.ExecuteDataTable(ConnStrLzEmr, esql1, new OracleParameter(":mrn", mrn));

            //获取西岛电子病历
            string esql2 = "select * from his_cpr_pr where mrn=@mrn";
            DataTable edt2 = MsSqlHelper.ExecuteDataTable(ConnStrSIEmr, esql2, new SqlParameter("@mrn", mrn));

            //获取lis检验结果(方格)
            string lsql = "select * from v_lis_xm where MRN=:mrn";
            DataTable ldt = OracleHelper.ExecuteDataTable(ConnStrLis, lsql, new OracleParameter(":mrn", mrn));

            //获取pacs报告
            string psql = "select * from VHIS_TL where MRN=:mrn";
            DataTable pdt = OracleHelper.ExecuteDataTable(ConnStrPacs, psql, new OracleParameter(":mrn", mrn));

            //获取ecg报告和图片
            string ecsql = "select * from v_ecg_report where MRN=@mrn";
            DataTable ecdt = MsSqlHelper.ExecuteDataTable(EcgConnStr, ecsql, new SqlParameter("@mrn", mrn));

            //获取生命体征
            string ewllsql = "select * from v_ewll_info where MRN=:mrn";
            DataTable ewlldt = OracleHelper.ExecuteDataTable(ConnStrLzHis, ewllsql, new OracleParameter(":mrn", mrn));

            //获取lis检验结果(联众)
            string lsql1 = "select * from v_lis_xm where MRN=:mrn";
            DataTable ldt1 = OracleHelper.ExecuteDataTable(ConnStrLis1, lsql1, new OracleParameter(":mrn", mrn));

            //linq联合查询并按时间排序
            var q = from dt9 in
                        (
                            (
                                from dt1 in ldt.AsEnumerable()
                                select dt1
                            ).Union(
                                from dt2 in edt.AsEnumerable()
                                select dt2
                            ).Union(
                                from dt3 in pdt.AsEnumerable()
                                select dt3
                            ).Union(
                                from dt4 in ecdt.AsEnumerable()
                                select dt4
                            ).Union(
                                from dt5 in edt1.AsEnumerable()
                                select dt5
                            ).Union(
                                from dt6 in ewlldt.AsEnumerable()
                                select dt6
                            ).Union(
                                from dt7 in ldt1.AsEnumerable()
                                select dt7
                            ).Union(
                                from dt8 in edt2.AsEnumerable()
                                select dt8
                            )
                        ).AsEnumerable()
                    orderby dt9.Field<string>("DODATE") descending
                    select dt9;

            if (q.Any() == false)
            {
                dt = null;
            }
            else
            {
                dt = q.CopyToDataTable();
            }
            return dt;
        } 
View Code

 

 

posted @ 2018-01-23 14:42  flywong  阅读(462)  评论(0编辑  收藏  举报