zzzprojects / EntityFramework-Effort

Entity Framework Effort is a powerful tool that enables a convenient way to create automated tests for Entity Framework based applications.
https://entityframework-effort.net/
MIT License
431 stars 99 forks source link

Exception querying context during unit test #207

Closed EricHurt closed 3 years ago

EricHurt commented 3 years ago

Description

After saving changes in the context, querying them causes an exception with the following error. I cannot call FirstOrDefault, Where, ToList, etc. etc.

_context.Table.Find seems to work, but that is the only method of querying the context available.

Exception

System.Data.Entity.Core.EntityCommandExecutionException : An error occurred while executing the command definition. See the inner exception for details. ---- System.ArgumentNullException : Value cannot be null. Parameter name: sql Stack Trace: EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues) <>cDisplayClass7.b6() ObjectContext.ExecuteInTransaction[T](Func1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) <>c__DisplayClass7.<GetResults>b__5() DefaultExecutionStrategy.Execute[TResult](Func1 operation) ObjectQuery1.GetResults(Nullable1 forMergeOption) IEnumerable.GetEnumerator>b0() LazyEnumerator1.MoveNext() Enumerable.FirstOrDefault[TSource](IEnumerable1 source) ObjectQueryProvider.b1[TResult](IEnumerable1 sequence) ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable1 query, Expression queryRoot) IQueryProvider.Execute[TResult](Expression expression) DbQueryProvider.Execute[TResult](Expression expression) Queryable.FirstOrDefault[TSource](IQueryable1 source) SettingsMarketingToolsRepositoryTests.SomeTest() line 32 ----- Inner Stack Trace ----- QueryRegistrar.ContainsQuery(MetadataWorkspace workspace, String sql) CachingCommand.get_IsQueryAlwaysCached() CachingCommand.get_IsCacheable() CachingCommand.ExecuteDbDataReader(CommandBehavior behavior) DbCommand.ExecuteReader(CommandBehavior behavior) DbCommandDispatcher.<Reader>b__c(DbCommand t, DbCommandInterceptionContext1 c) InternalDispatcher1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func3 operation, TInterceptionContext interceptionContext, Action3 executing, Action3 executed) DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext) InterceptableDbCommand.ExecuteDbDataReader(CommandBehavior behavior) DbCommand.ExecuteReader(CommandBehavior behavior) EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)

Note: If you are not able to provide code we can run and that reproduce the issue, we will not be able to fix it either.

Example

        public SettingsMarketingToolsRepositoryTests()
        {
            var connection = Effort.DbConnectionFactory.CreateTransient();

            _context = new SettingsDbContext(connection);

            _context.Database.CreateIfNotExists();
        }

        [Fact]
        public void SomeTest()
        {
            _context.TblMarketingTools.Add(new TblMarketingTool { ToolId = 1, MsClient = _msClient, Name = "Tool1", Description = "Description 1" });
            _context.SaveChanges();
            var tool = _context.TblMarketingTools.FirstOrDefault();
        }

Further technical details

JonathanMagnan commented 3 years ago

Hello @Wheater ,

Do you think you could provide a runnable project sample for this issue? It will help my developer to get started to investigate it faster and make sure nothing is missing.

Providing a project sample is now REQUIRED. It happened too many times that something was missing to investigate and/or answer an issue.

Try to create a new project with only the minimal code (having too many non-related codes doesn’t help either).

You can send it to info@zzzprojects.com if you need to keep the source private

Best Regards,

Jon


Performance Libraries context.BulkInsert(list, options => options.BatchSize = 1000); Entity Framework ExtensionsEntity Framework ClassicBulk OperationsDapper Plus

Runtime Evaluation Eval.Execute("x + y", new {x = 1, y = 2}); // return 3 C# Eval FunctionSQL Eval Function

EricHurt commented 3 years ago

@JonathanMagnan Honestly, I don't think it's feasible at this point and I have too many deadlines to meet. Maybe I can revisit this in the future.

JonathanMagnan commented 3 years ago

No problem,

Just let us know whenever you can provide an example and we will re-open the issue.

Best Regards,

Jon