question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

11G .net core 3.1 beta | linq query exception when relating classes

See original GitHub issue

I was unable to reopen and I’m unsure if you get notifications so opening a new one for 11G. Apologies if I’m doing this wrong.

Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - Production PL/SQL Release 11.2.0.4.0 - Production CORE 11.2.0.4.0 Production TNS for Linux: Version 11.2.0.4.0 - Production NLSRTL Version 11.2.0.4.0 - Production

` public class DaleContext : DbContext { public DaleContext() { ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; }

public DaleContext(DbContextOptions options) : base(options)
{
  ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
}

public DaleContext(DbContextOptions<SecurityContext> options) : base(options)
{
  ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
}
public DbSet<BookingBlock> BookingBlocks { get; set; }
public DbSet<CustomerGroup> CustomerGroups { get; set; }

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
  //leaving this for now to use for direct db integration/validation in unit test
  if (!optionsBuilder.IsConfigured)
  {
    //if this does remain, then pull data source string from json file where it's NOT stored in git
    optionsBuilder
      .UseLoggerFactory(ConsoleLoggerFactory)
      .UseOracle("Data Source = xxxx;"
      , b => b.UseOracleSQLCompatibility("11"));
  }
}

public static readonly ILoggerFactory ConsoleLoggerFactory =
  LoggerFactory.Create(builder =>
  {
    builder.AddFilter((category, level) =>
      category == DbLoggerCategory.Database.Command.Name && level == LogLevel.Information).AddConsole();
  });

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
  modelBuilder.Entity<BookingBlock>().ToTable("PDF_BOOKING_BLOCK");
  modelBuilder.Entity<BookingLimit>().ToTable("PDF_BOOKING_LIMIT");
  modelBuilder.Entity<CustomerGroup>().ToTable("PDF_CUST_GROUP");

  //one to many
  modelBuilder.Entity<CustomerGroup>().HasMany(cg => cg.BookingBlocks).WithOne(bb => bb.CustomerGroup);

  //tables w/ composite keys
  modelBuilder.Entity<BookingBlock>()
      .HasKey(pk => new { pk.RPTNG_FLOW_PATH_ID, pk.CUST_GROUP_IDFTN });

}`

public class CustomerGroup { public CustomerGroup() { BookingBlocks = new List<BookingBlock>(); } [Key] public int CUST_GROUP_IDFTN { get; set; } public string CUST_GROUP_NAME { get; set; } public string CUST_GROUP_DESC { get; set; } public string ENABLED_INDIC { get; set; } public string LAST_CHNGD_IDFTN { get; set; } public DateTime DATE_CRTD { get; set; } public DateTime DATE_LAST_CHNGD { get; set; } public List<BookingBlock> BookingBlocks { get; set; } }

public class BookingBlock { public int RPTNG_FLOW_PATH_ID { get; set; } public int CUST_GROUP_IDFTN { get; set; } public int BLOCK_MIN_LEAD_TIME { get; set; } public int BLOCK_BKNG_WEEKS { get; set; } public string ENABLED_INDIC { get; set; } public int SORT_SEQ { get; set; } public string LAST_CHNGD_IDFTN { get; set; } public DateTime DATE_CRTD { get; set; } public DateTime DATE_LAST_CHNGD { get; set; } public CustomerGroup CustomerGroup { get; set; } }

1st test method

This test method used to work but after upgrade to 11G, it no longer does a simple count: NOTE: When I comment out the fluent relationship and the CustomerGroup property from BookBlock, then the first test method works. [TestMethod] public void GetBookBlockCountExample() { using (var context = new DaleContext()) { var bookingBlocks = context.BookingBlocks.ToList(); Console.WriteLine($"count {bookingBlocks.Count}"); } }

Exception for 1st test method

Message: Test method Arconic.UnitTest.Core.DaleUnitTest.GetBookBlockCountExample threw exception: Oracle.ManagedDataAccess.Client.OracleException: ORA-00904: “p”.“CustomerGroupCUST_GROUP_IDFTN”: invalid identifier Stack Trace: OracleConnectionImpl.VerifyExecution(Int32& cursorId, Boolean bThrowArrayBindRelatedErrors, SqlStatementType sqlStatementType, Int32 arrayBindCount, OracleException& exceptionForArrayBindDML, Boolean& hasMoreRowsInDB, Boolean bFirstIterationDone) OracleCommandImpl.ExecuteReader(String commandText, OracleParameterCollection paramColl, CommandType commandType, OracleConnectionImpl connectionImpl, OracleDataReaderImpl& rdrImpl, Int32 longFetchSize, Int64 clientInitialLOBFS, OracleDependencyImpl orclDependencyImpl, Int64[] scnForExecution, Int64[]& scnFromExecution, OracleParameterCollection& bindByPositionParamColl, Boolean& bBindParamPresent, Int64& internalInitialLOBFS, OracleException& exceptionForArrayBindDML, OracleConnection connection, OracleLogicalTransaction& oracleLogicalTransaction, IEnumerable1 adrianParsedStmt, Boolean isDescribeOnly, Boolean isFromEF) OracleCommand.ExecuteReader(Boolean requery, Boolean fillRequest, CommandBehavior behavior) OracleCommand.ExecuteDbDataReader(CommandBehavior behavior) DbCommand.ExecuteReader() OracleRelationalCommand.ExecuteReader(RelationalCommandParameterObject parameterObject) Enumerator.InitializeReader(DbContext _, Boolean result) OracleExecutionStrategy.Execute[TState,TResult](TState state, Func3 operation, Func3 verifySucceeded) Enumerator.MoveNext() List1.ctor(IEnumerable1 collection) Enumerable.ToList[TSource](IEnumerable1 source) DaleUnitTest.GetBookBlockCountExample() line 29

This is the test method I used w/ 10G and it responds the same in 11G. Could it be the composite key of the child class BookBlock?

2nd test method

[TestMethod] public void Get_AmCastleCompany_FlowPath_27NFT_BookingWeeks() { //relationships not working in 10G because ODP using (var context = new DaleContext()) { var customer = context.CustomerGroups.Where(cg => cg.CUST_GROUP_IDFTN == 275 && cg.BookingBlocks.FirstOrDefault().RPTNG_FLOW_PATH_ID == 2).ToList(); Assert.AreEqual(1, customer.Count); } }

The exception for 2nd test method:

Message: Test method Arconic.UnitTest.Core.DaleUnitTest.Get_AmCastleCompany_FlowPath_27NFT_BookingWeeks threw exception: Oracle.ManagedDataAccess.Client.OracleException: ORA-00904: “p0”.“CustomerGroupCUST_GROUP_IDFTN”: invalid identifier Stack Trace: OracleConnectionImpl.VerifyExecution(Int32& cursorId, Boolean bThrowArrayBindRelatedErrors, SqlStatementType sqlStatementType, Int32 arrayBindCount, OracleException& exceptionForArrayBindDML, Boolean& hasMoreRowsInDB, Boolean bFirstIterationDone) OracleCommandImpl.ExecuteReader(String commandText, OracleParameterCollection paramColl, CommandType commandType, OracleConnectionImpl connectionImpl, OracleDataReaderImpl& rdrImpl, Int32 longFetchSize, Int64 clientInitialLOBFS, OracleDependencyImpl orclDependencyImpl, Int64[] scnForExecution, Int64[]& scnFromExecution, OracleParameterCollection& bindByPositionParamColl, Boolean& bBindParamPresent, Int64& internalInitialLOBFS, OracleException& exceptionForArrayBindDML, OracleConnection connection, OracleLogicalTransaction& oracleLogicalTransaction, IEnumerable1 adrianParsedStmt, Boolean isDescribeOnly, Boolean isFromEF) OracleCommand.ExecuteReader(Boolean requery, Boolean fillRequest, CommandBehavior behavior) OracleCommand.ExecuteDbDataReader(CommandBehavior behavior) DbCommand.ExecuteReader() OracleRelationalCommand.ExecuteReader(RelationalCommandParameterObject parameterObject) Enumerator.InitializeReader(DbContext _, Boolean result) OracleExecutionStrategy.Execute[TState,TResult](TState state, Func3 operation, Func3 verifySucceeded) Enumerator.MoveNext() List1.ctor(IEnumerable1 collection) Enumerable.ToList[TSource](IEnumerable1 source) DaleUnitTest.Get_AmCastleCompany_FlowPath_27NFT_BookingWeeks() line 62

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
alexkehcommented, Jun 9, 2020

I reproduced the problem and found a solution.

In OnModelCreating, add the following line: modelBuilder.HasAnnotation("Relational:MaxIdentifierLength", 30);

Oracle DBs prior to version 12.2 have a 30 character limit on object names, which includes quotes. Quotes are appended to the EF Core object names, which put your 29 character object over the limit.

Once I set the MaxIdentifierLength property to 30, I was able to create your schema objects and execute the test you provided.

1reaction
alexkehcommented, Jun 9, 2020

I got your test case working against a 19c DB without the error. I’ll get a hold of 11g test DB tomorrow and try it out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

10G .net core 3.1 beta | linq query exception when relating ...
It appears to exclude the dot between BookingBlock alias class and the property. I've tweaked my classes and now I get a 00936...
Read more >
Upgraded to .NET Core 3.1 and receiving an error in a ...
You have alot of FirstOrDefault (s) calls. To code them "safely", you can try this: .FirstOrDefault() ?? string.Empty.
Read more >
Handle exceptions in query expressions (LINQ in C#)
This example shows how to avoid raising exceptions when you call methods in a query expression without violating the general .NET guidelines ...
Read more >
dotConnect for Oracle History
The detailed history of all changes and bugfixes made in dotConnect for Oracle.
Read more >
Known Issues and Considerations in LINQ to Entities
In this article · LINQ Queries That cannot be Cached · Ordering Information Lost · Unsigned Integers Not Supported · Type Conversion Errors....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found