Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting a string[] from a UDF #17025

Closed
TehWardy opened this issue Aug 8, 2019 · 1 comment
Closed

Getting a string[] from a UDF #17025

TehWardy opened this issue Aug 8, 2019 · 1 comment

Comments

@TehWardy
Copy link

TehWardy commented Aug 8, 2019

I can't seem to find anything about table valued functions in EF core is this even possible.
Here's a sample of what I would like to achieve ...

I have a role class that looks like this ...

[Table("Roles", Schema = "Security")]
public class Role 
{
     [Key]
     public Guid Id { get; set; }

     // this is a csv list of "privilege keys" that the role grants
     public string Privs { get; set; }
     ...
}

Add this to my DbContext ...

[DbFunction("[DMS].[GetFolderPrivList]")]
public static string[] GetFolderPrivList(string userId, Guid folderId)
{
    throw new Exception();
}

Then I have a UDF like this to compute a list of privs for a folder "path" (which recursively crawls the tree for inherited permissions) ...

CREATE FUNCTION [DMS].[GetFolderPrivList] 
(	@UserId nvarchar(450),
	@FolderId uniqueidentifier
)
RETURNS @PrivList TABLE ( priv nvarchar(100) NOT NULL)
AS
BEGIN
	INSERT INTO @PrivList (priv)
		SELECT DISTINCT *
		  FROM STRING_SPLIT((SELECT R.Privs FROM DMS.Folders P
		  JOIN [Security].FolderRoles PR ON FR.FolderId= P.Id
		  JOIN [Security].Roles R ON R.Id= FR.RoleId
		  JOIN [Security].UserRoles UR ON UR.RoleId = R.Id
		  WHERE P.Id=@FolderId AND UR.UserId=@UserId),',');

	IF (SELECT ParentId FROM [DMS].[Folders] WHERE Id=@FolderId) IS NOT NULL
	BEGIN
		INSERT INTO @PrivList (priv)
			SELECT priv
			  FROM [DMS].[GetFolderPrivList](@UserId,(SELECT ParentId FROM CMS.Pages WHERE Id=@FolderId))
			  WHERE priv NOT IN (SELECT priv FROM @PrivList)
	END	--*/
	RETURN
END;

I can't get EF to accept this such that I can make the call in a linq query, for example ...

db.GetAll<Folder>().FirstOrDefault(f => f.AppId == app.Id && f.Path.ToLower() == path.Lowered && CoreDataContext.GetFolderPrivList(user.Id, f.Id).Contains(privKey))
@ajcvickers
Copy link
Member

Duplicate of #4319

@ajcvickers ajcvickers marked this as a duplicate of #4319 Aug 9, 2019
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants