[ValidateRequest(Condition = "!dbExistsSync('SELECT * FROM RockstarAlbum WHERE RockstarId = @Id', { it.Id })",
ErrorCode = "HasForeignKeyReferences")]
Yet anytime I try this, it errors out with
Filter in ‘{temp file}’ named ‘dbExistsSync’ was not found. No similar filters named ‘dbExists’ were found in registered filter(s): ‘DefaultScripts’, ‘HtmlScripts’, ‘ProtectedScripts’, ‘InfoScripts’, ‘ServiceStackScripts’, ‘ValidateScripts’, ‘BootstrapScripts’, ‘MarkdownScriptMethods’.
I have SharpPagesFeature enabled:
Plugins.Add(new SharpPagesFeature()
{
ScriptMethods =
{
new DbScripts()
},
});
Unsure if I need to enable scripts for Database usage somewhere else?
My Actual Code:
[ValidateRequest(Condition = "dbExists('SELECT * FROM Projects WHERE Id = @Id AND CreatedBy = @CreatedBy', { it.Id, userAuthId })")]
Just doing some lightweight security checks for an MVP
If I change it to DbScriptsAsync, then update the script to
[ValidateRequest(Condition = "dbExists('SELECT * FROM Project WHERE Id = @Id AND CreatedBy = @CreatedBy', { it.Id, userAuthId })")]
It still gives the same error
Filter in ‘{temp file}’ named ‘dbExists’ was not found. No similar filters named ‘dbExists’ were found in registered filter(s): ‘DefaultScripts’, ‘HtmlScripts’, ‘ProtectedScripts’, ‘InfoScripts’, ‘ServiceStackScripts’, ‘ValidateScripts’, ‘BootstrapScripts’, ‘MarkdownScriptMethods’.
You should continue to use sync APIs in Condition attributes as per the docs, i.e. dbExistsSync.
But the error message says DbScriptsAsync does not exist. So something is wrong with your registration. Are you registering the SharpPagesFeature plugin in your AppHost?
Otherwise use ScriptContext which will use the default ScriptContext if SharpPagesFeature plugin does not exist, e.g:
ScriptContext.ScriptMethods.AddRange(new ScriptMethods[] {
new DbScriptsAsync(),
});