Dortimer
Dortimer

Reputation: 617

ORA-00904 Occasional Invalid identifier with linq query

I have two different linq expressions that are referencing the same column in the database. One works just fine, but the other throws an invalid identifier exception (ORA-00904).

Most of the questions I've found feature naked sql queries with some syntax errors. Others have to do with the entity model, but seeing as how it doesn't run into the issue in one query, I'm not convinced the issue is with the model.

The one that works:

    public List<DateTime> GetAvailableDates()
    {
        var retData = new List<DateTime>();

        using (var context = new CASTDbContext())
        {
            var result = context.SomeDataEntity.Select(x => x.CAPTURE_DATE).Distinct().ToList();          
            if(result != null && result.Count > 0)
            {
                retData = result;
            }
        }

        return retData;
    }

The one that doesn't work:

    public List<SomeDataModel> GetSomeDataByDate(DateTime date)
    {
        var retData = new List<SomeDataModel>();

        using (var context = new SomeDbContext())
        {                
            var result = context.SomeDataEntity
                .Where( y => DbFunctions.TruncateTime(y.CAPTURE_DATE) == date.Date).ToList(); // the line that's throwing the exception

            if (result != null && result.Count > 0)
            {
                foreach (var item in result)
                {
                    retData.Add(mapper.Map<SomeDataModel>(item));
                }
            }
        }

        return retData;
    }

Upvotes: 0

Views: 689

Answers (1)

Dortimer
Dortimer

Reputation: 617

The issue ended up being a different part of the model, but just some info on Oracle perils:

The first query worked fine because it was only referencing one specific field that had a matching column in the database (oracle doesn't care about the rest of the model in that instance for some reason).

The second query didn't work because it was trying to pull every column from the table, and there was one field missing from the model.

Upvotes: 0

Related Questions