I have a table of entities (let's say documents), where each document may have a different entity connected to it (let's say permission). A permission has a foreign key to the document table.
Example:
Schema:
Document -> Id | Data
Permission -> Id | EntityId | PermissionData
Content:
Document -> 1 | "This is my first doc"
Permission -> 12 | 1 | "This is doc 1's permission set"
If Permission
was a table, I wouldn't have any problem - I would have simply use the Include
method in my query and receive the connected permission:
ctx.Include(d => d.Permission)...
However, Permission
is actually a complex scheme that includes multiple tables and is computed using a SQL Server table-valued function.
I'm trying to create a Permission
entity, like every regular table entity, and simply configure Entity Framework to execute a database function call instead of a table join.
If permission was a table and I would have included it in my query, I would expect the SQL execution to look something like this:
select *
from document d
join permission p on d.Id = p.EntityId
Instead of that, I would like to achieve something like this:
select *
from document d
join fn_getPermissions(p1,p2,p3...) p on d.Id = p.EntityId
Let's assume that the params p1...pn are hard coded, but I need to default them on the C# end and not in SQL Server.
I saw an option to configure an entity to use stored procedures using Entity Framework, but I didn't see any place I can use a stored procedure for querying, rather for insert, delete etc.
I know how to call DBFunctions
(using Conventions
) - I'm not looking for explicit function calls. I would like to treat the Permission entity as a table entity, mainly since I'm using OData over Entity Framework and I don't want to create specific methods just for this case.
Is there any way to accomplish this kind of behavior? I'm using EF 6.x (not core).