EF6 Data Won't Load From Database

Jun 6, 2014 at 3:28 PM
I upgraded one of our projects to EF6 this week and spent yesterday trying to get unit testing working again to no avail. I downloaded the latest build (Effort.1.0.0-beta5-140316) and updated the effort dll in the project to the one targeting EF6. Specifically, I can get it running with no data loaded, but when I try to load data from our unit testing database I keep getting this error:
Assembly Initialization method UnitTests.Tests.TestingSetup.SetUp threw exception. Effort.Exceptions.EffortException: Effort.Exceptions.EffortException: Unhandled exception while trying to initialize the content of 'Table<____RefactorLog>' table ---> System.NullReferenceException: Object reference not set to an instance of an object.. Aborting test execution.
Note, it doesn't seem to be a problem with that particular table, it's just the first one it tries to load data for. When I deleted it from the model and tried again it just went to the next one in alphabetical order and threw the same error.

Here's my current initialization code:
Effort.Provider.EffortProviderConfiguration.RegisterProvider();
IDataLoader wrappedDataLoader = new EntityDataLoader("metadata=res://*/Model.Model.csdl|res://*/Model.Model.ssdl|res://*/Model.Model.msl;provider=System.Data.SqlClient;provider connection string='Server=server;Database=database;User ID=userid;Password=password;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;multipleactiveresultsets=True;App=EntityFramework'");
var loader = new CachingDataLoader(wrappedDataLoader, false);
EntityConnection connection = Effort.EntityConnectionFactory.CreateTransient("metadata=res://*/Model.Model.csdl|res://*/Model.Model.ssdl|res://*/Model.Model.msl;provider=System.Data.SqlClient;provider connection string='Server=server;Database=database;User ID=userid;Password=password;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;multipleactiveresultsets=True;App=EntityFramework'", loader);
EntityFrameworkUnitOfWorkFactory.SetObjectContext(() => new DataEntities(connection));
If I don't specify the loader when creating the EntityConnection it works, but of course most of the tests fail at that point. I also was able to load data from CSV files, but this is a poor solution for multiple reasons. (Harder to maintain, could never get working on our build server, etc.)

For what it's worth, I also added the following to my app.config file:
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
      <provider invariantName="EffortProvider" type="Effort.Provider.EffortProviderServices, Effort" />
    </providers>
  </entityFramework>
    <system.data>
        <DbProviderFactories>
            <add name="Effort.Provider"
                 invariant="Effort.Provider"
                 description="Effort.Provider"
                 type="Effort.Provider.EffortProviderFactory, Effort" />
        </DbProviderFactories>
    </system.data>
I'm stumped at this point. Before moving to EF6 I was using the ObjectContextFactory and it was fine, but that's not really an option anymore without reworking a lot of code in our repository framework.

Any ideas at this point would be great. I did download the source and tried to run against that so I could see the specific error being thrown instead of the generic one throw by Effort, but I couldn't get it to run against the source at all.
Coordinator
Jun 6, 2014 at 4:55 PM
Hello,

Thank you for reporting this issue.

Could you provide me a more detailed stack trace?
Jun 9, 2014 at 2:44 PM
Edited Jun 9, 2014 at 2:46 PM
Here's a full stack trace:
UnitTests.Tests.TestingSetup.SetUp threw exception. Effort.Exceptions.EffortException: Effort.Exceptions.EffortException: Unhandled exception while trying to initialize the content of 'Table<____RefactorLog>' table ---> System.NullReferenceException: Object reference not set to an instance of an object.. Aborting test execution.

StackTrace: 
at Effort.Internal.Common.CommandTreeBuilder.CreateSelectAll(MetadataWorkspace workspace, EntitySet entitySet)
   at Effort.DataLoaders.EntityTableDataLoader.CreateDataReader()
   at Effort.DataLoaders.TableDataLoaderBase.<GetData>d__0.MoveNext()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at Effort.DataLoaders.CachingTableDataLoader..ctor(ITableDataLoader tableDataLoader)
   at Effort.DataLoaders.CachingTableDataLoaderFactory.CreateCachedData(TableDescription table)
   at Effort.DataLoaders.CachingTableDataLoaderFactory.<>c__DisplayClass1.<CreateTableDataLoader>b__0()
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at System.Lazy`1.get_Value()
   at Effort.Internal.Caching.ConcurrentCache`2.Get(TKey key, Func`1 factory)
   at Effort.Internal.Caching.CachingTableDataLoaderStore.GetCachedData(CachingTableDataLoaderKey key, Func`1 factoryMethod)
   at Effort.DataLoaders.CachingTableDataLoaderStoreProxy.GetCachedData(CachingTableDataLoaderKey key, Func`1 factoryMethod)
   at Effort.DataLoaders.CachingTableDataLoaderFactory.CreateTableDataLoader(TableDescription table)
   at Effort.DataLoaders.ObjectLoader.<Load>d__0.MoveNext()
   at System.Linq.Enumerable.<CastIterator>d__b1`1.MoveNext()
   at Effort.Internal.DbManagement.Engine.ExtendedTable`2.Initialize(IEnumerable`1 entities)
   at Effort.Internal.Common.DatabaseReflectionHelper.WrapperMethods.InitializeTableData[TEntity](ITable`1 table, IEnumerable`1 entities)
 --- End of inner exception stack trace ---
    at Effort.Internal.Common.DatabaseReflectionHelper.InitializeTableData(ITable table, IEnumerable`1 entities)
   at Effort.Internal.DbManagement.DbContainer.Initialize(DbSchema schema)
   at Effort.Internal.DbManagement.DbContainer.Initialize(StoreItemCollection edmStoreSchema)
   at Effort.Provider.EffortProviderServices.DbCreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection)
   at System.Data.Entity.Core.Common.DbProviderServices.CreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection)
   at System.Data.Entity.Core.Objects.ObjectContext.CreateDatabase()
   at Effort.EntityConnectionFactory.CreateEntityConnection(MetadataWorkspace metadata, DbConnection connection)
   at Effort.EntityConnectionFactory.CreateTransient(String entityConnectionString, IDataLoader dataLoader)
   at UnitTests.MockRepository.MockRepositoryInitializer.Initialize() in h:\Users\devin\Documents\Git\LeadManager\CraftJack.UnitTests\MockRepository\MockRepositoryInitializer.cs:line 38
   at UnitTests.MockRepository.MockServicesInitializer.Initialize() in h:\Users\devin\Documents\Git\LeadManager\CraftJack.UnitTests\MockRepository\MockServicesInitializer.cs:line 14
   at UnitTests.Tests.TestingSetup.SetUp(TestContext testContext) in h:\Users\devin\Documents\Git\LeadManager\CraftJack.UnitTests\Tests\TestingSetup.cs:line 18
Coordinator
Jun 9, 2014 at 9:45 PM
I fixed your issue and also published the first stable release. Let me know if it worked out for you!
Jun 10, 2014 at 10:44 PM
Thanks for the quick work! It seems like that fixed the immediate problem I was having, although I'm running into an unrelated one now. I'm pretty sure it has nothing to do with Effort and everything to do with the way our repository framework is set up though.