I have a table that has records like:
DECLARE @path NVARCHAR(255) = '~/Root/SecondFolder/%'
WHERE VirtualPath LIKE @path
AND LEN(LEFT([VirtualPath], LEN([VirtualPath]) - (CHARINDEX('/', REVERSE([VirtualPath])) - 1))) < (LEN(@path) + 1)
There may be a better way to write this LINQ express but this should work:
string param = "~/Root/SecondFolder/"; string filter = files.Where(x => (x.StartsWith(param) && !x.Substring(param.Length, x.Length - param.Length).Contains('/'))).ToArray();
The performance constraint comes from Splitting the strings. That's the only way I could think of making sure that you are in the right Directory.
Maybe someone else could think of a better way to write that.
EDITED: Splitting strings is not supported by Entity Framework. Created an even uglier query but still works.