最近项目中采用框架Entity Framework 4.1和Linq进行开发,但是Oracle数据表中的主键值采用了序列生成自增值,必然项目中在增加记录时要查询获取当前表的序列值。

查询序列方法:

View Code
public Decimal GetProblemXH()
        {
            Decimal maxXh = 90000000;
            using (ModuleZJKEntities entity = new ModuleZJKEntities())
            {
                String strDBType = ((System.Data.EntityClient.EntityConnection)(entity.Connection)).StoreConnection.ToString();
                if (entity != null)
                {
                    string strSeqIDQuerySQL;
                    if (strDBType == "System.Data.SqlClient.SqlConnection")
                    {
                        strSeqIDQuerySQL = "insert into dual(NewDate) values(GETDATE()) select @@identity";
                    }
                    else
                    {
                        strSeqIDQuerySQL = "select SQE_ZJ_FYWT.nextval from dual";
                    }
                    Decimal decSeqID = entity.ExecuteStoreQuery<Decimal>(strSeqIDQuerySQL).First();
                    maxXh = decSeqID;
                }
            }
            return maxXh;
        }

 

下一步将会研究执行调用存储过程的方法,如果大家有好的方法希望能贴出来共同学习~~~

相关文章:

  • 2021-12-28
  • 2021-12-18
  • 2022-12-23
  • 2022-12-23
  • 2022-01-07
猜你喜欢
  • 2021-07-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案