简体   繁体   English

Oracle实体框架C#

[英]Oracle Entity Framework C#

I'm using an Oracle 11g database with the ADO.NET Entity Data Model. 我正在将Oracle 11g数据库与ADO.NET实体数据模型一起使用。 Every now and then I run into this error and I have no idea what's causing it. 我时不时地碰到这个错误,不知道是什么原因造成的。 I'm assuming it's something in the EDMX file or the designer file for it but I can't seem to figure it out. 我假设它在EDMX文件或设计器文件中,但是我似乎无法弄清楚。 I've deleted the model, added it, updated, etc multiple times and can't figure out the issue. 我已多次删除,添加,更新模型等操作,无法解决问题。 It works on other pages but this one seems to be a problem. 它可以在其他页面上运行,但是这似乎是一个问题。

This has happened before, but simply removing and re-adding the table worked. 这以前已经发生过,但是只需删除并重新添加表即可。 Any ideas on how to fix this? 有想法该怎么解决这个吗?

            using (ODSData.Entities entities = new Entities())
        {
            var info = from item in entities.ODS_VALIDATIONRULE
                       select item;

            newPK = Convert.ToInt32(info.Max(p => p.VALIDATIONRULEID)) + 1;

            try
            {
                ODS_VALIDATIONRULE newRule = new ODS_VALIDATIONRULE();

                newRule.ALLOWNULLIND = isNull;
                newRule.CREATEDATE = DateTime.Now;
                newRule.FAILIND = isFail;
                newRule.MAXVALUEFACTOR = max;
                newRule.MINVALUEFACTOR = min;
                newRule.RULEDESCRIPTION = description;
                newRule.SOURCESYSTEM = source;
                newRule.TABLENAME = table;
                newRule.COLUMNNAME = column;
                newRule.DATATYPE = datatype;
                newRule.VALIDVALUELIST = valid;
                newRule.VALIDATIONRULEID = newPK;
                entities.AddToODS_VALIDATIONRULE(newRule);
                entities.SaveChanges();
                insertAccepted = true;

            }
            catch
            {
                // Log Error
            }

The error I'm getting is this: "An error occurred while preparing the command definition. See the inner exception for details." 我得到的错误是:“在准备命令定义时发生错误。有关详细信息,请参阅内部异常。”

Inner Exception: "Operation is not valid due to the current state of the object." 内部异常:“由于对象的当前状态,该操作无效。”

Apparently the issue here was somewhere in the EDMX file and the way it read from Oracle. 显然,这里的问题在EDMX文件中以及它从Oracle读取的方式中。 I deleted the table and recreated it in the DB as well as the EDMX and then added it back. 我删除了该表,并在数据库和EDMX中重新创建了该表,然后将其重新添加。 It worked fine then. 当时效果很好。

The only thing I see that seems odd is you aren't using a sequence for your Pk value. 我看到的唯一一件奇怪的事情是您没有使用序列作为Pk值。 You may try creating one and see if that helps at all. 您可以尝试创建一个,看看是否有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM