guys.
I have a question about EF Core DbCommandInterceptor.
Let's have a class with 2 fields like this
public class User
{
public Guid Id { get; set; }
public string SameData { get; set; }
}
public class TestClass
{
public Guid Id { get; set; }
public Guid TestClassId { get; set; }
[NotMapperd, MyAttr]
public TestClass TestClass { get; set; }
}
where User
and TestClass
are both located in the different contexts (for example, UserDbContext
, TestDbContext
). MyAttr
is the marker attribute, nothing more.
So, I want to write an interceptor that raises up each time we try to get info about TestClass
es, but after data got it should get an additional data about User with cross-request to UserDbContext (It possible, because I have User
Id
after the command execution and can use this Id
in the request)
I know, that it should be DbCommandInterceptor.ReaderExecuted
or DbCommandInterceptor.ReaderExecutedAsync
in this case, but I cannot understand how to get information about objects in the result (I can get rows but I cannot understand what should I do, how should I map it). I can use additional libraries in the project if needed (like Dapper and others).
Could anyone helps me to get
- Result Type - concrete entity type or entity collection type?
- Result as a C# object (POCO or POCO collection)?
Thank you.
CodePudding user response:
I know, that it should be DbCommandInterceptor.ReaderExecuted or DbCommandInterceptor.ReaderExecutedAsync in this case, but I cannot understand how to get information about objects in the result
The EF Command interceptors don't support that. You can replace the DataReader with a different one. But the query was generated to fill a particular object graph, which is not exposed by the interceptor API.