I am trying to Mock EF on IDBcommandInterceptor
For insert / update operations it is enough simple - I can return a DbDataReader
made of a single field or an int
However, for select operations, if there are some "include", then the shape of the sql result is pretty ... awesome
How could I obtain from
ReaderExecuting(DbCommand command, DbCommandInterceptionContext<DbDataReader>
the fields and the names and the corresponding entities for the DbDataReader
result?
Thank you,
Example : Trying to read Department(Id, Name) from Id with include on Employee(Id, Name .IDDepartment, DateModification, DateCreation, User)
The Command that obtains the DBDataReader for an include is below .
I want to know the fields names (like C1
, ID1
, Name1
and others) to be capable of Mocking.
SELECT
[Project2].[Id] AS [Id],
[Project2].[Name] AS [Name],
[Project2].[C1] AS [C1],
[Project2].[Id1] AS [Id1],
[Project2].[Name1] AS [Name1],
[Project2].[IDDepartment] AS [IDDepartment],
[Project2].[DateModification] AS [DateModification],
[Project2].[DateCreation] AS [DateCreation],
[Project2].[User] AS [User],
[Project2].[Archive] AS [Archive]
FROM ( SELECT
[Limit1].[Id] AS [Id],
[Limit1].[Name] AS [Name],
[Extent2].[Id] AS [Id1],
[Extent2].[Name] AS [Name1],
[Extent2].[IDDepartment] AS [IDDepartment],
[Extent2].[DateModification] AS [DateModification],
[Extent2].[DateCreation] AS [DateCreation],
[Extent2].[User] AS [User],
[Extent2].[Archive] AS [Archive],
CASE WHEN ([Extent2].[Id] IS NULL) THEN CAST(NULL AS int) ELSE 1 END AS [C1]
FROM (SELECT TOP (1)
[Extent1].[Id] AS [Id],
[Extent1].[Name] AS [Name]
FROM [dbo].[Department] AS [Extent1]
WHERE [Extent1].[Id] = @p__linq__0 ) AS [Limit1]
LEFT OUTER JOIN [dbo].[Employee] AS [Extent2] ON [Limit1].[Id] = [Extent2].[IDDepartment]
) AS [Project2]
ORDER BY [Project2].[Id] ASC, [Project2].[C1] ASC
You should be able to get the column names from the reader by doing something like this
That in the case you only need the names. If you get the whole schema for the result table, you could get it by doing this:
And then iterate through the collection of rows in the datatable to get the properties of each column.
Does that help to answer your question?