I have a class calledModelSetWrapper which wraps model sets from an EfCore DbContext (Jet, specifically) and returns a dictionary containing the model set information. Here's what the class looks like: namespaceLibFacade.Utils;publicclassModelSetWrapper<T>whereT:class{privateDictionary<string,List<object>>_data;publicModelSetWrapper(){_data=newDictionary<string,List<object>>();PropertyInfo[]properties=typeof(T).GetProperties();using(ModelContextcontext=newModelContext()){DbSet<T>dbSet=context.Set<T>();foreach(PropertyInfopInfoinproperties){List<object>list=dbSet.Select(c=>pInfo.GetValue(c)).ToList();_data[pInfo.Name]=list;}}}publicDictionary<string,List<object>>Data=>_data;} This seems to work fine from the .NET side. From a console app, the following runs without any errors: ModelSetWrapper<Jaugeage>wrapper=newModelSetWrapper<Jaugeage>();foreach(KeyValuePair<string,List<object>>kvpinwrapper.Data){Console.WriteLine($"{kvp.Key},{kvp.Value.Count}");} I'm able to load this assembly and types from it using pythonnet without any issues. However when I attempt the following in my python code: wrapper = ModelSetWrapper[Jaugeage]()
I get an error: ---------------------------------------------------------------------------InvalidOperationException Traceback (most recent call last)Cell In[2], line 1----> 1 wrapper = ModelSetWrapper[Jaugeage]()InvalidOperationException: The property can only be set once. at EntityFrameworkCore.Jet.Data.JetConnection.set_DataAccessProviderFactory(DbProviderFactory value) at EntityFrameworkCore.Jet.Data.JetConnection.Open() at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenDbConnection(Boolean errorsExpected) at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternal(Boolean errorsExpected) at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(Boolean errorsExpected) at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReader(RelationalCommandParameterObject parameterObject) at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.Enumerator.InitializeReader(Enumerator enumerator) at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.Enumerator.<>c.<MoveNext>b__21_0(DbContext _, Enumerator enumerator) at EntityFrameworkCore.Jet.Storage.Internal.JetExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded) at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.Enumerator.MoveNext() at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) at LibFacade.Utils.ModelSetWrapper`1..ctor() in [C:\Users\admin\Desktop\TEMP\projects\317\notebooks\Lib\LibFacade\ModelSetWrapper.cs](file:///C:/Users/admin/Desktop/TEMP/projects/317/notebooks/Lib/LibFacade/ModelSetWrapper.cs):line 12 at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor) at System.Reflection.MethodBaseInvoker.InvokeConstructorWithoutAlloc(Object obj, Boolean wrapInTargetInvocationException)
I have searched far an wide for a solution but don't really know how to start tackling this. Any pointers would be very welcome. |