Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Cannot load an EF Core db context wrapper in Python using Python.NET#2567

Unanswered
awa5114 asked this question inQ&A
Discussion options

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.

You must be logged in to vote

Replies: 0 comments

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
1 participant
@awa5114

[8]ページ先頭

©2009-2025 Movatter.jp