简体   繁体   中英

Calling Method in Subsonic 3.0 ActiveRecord Query

I'm trying to run a custom method in subsonic query. Here is my query:

Page = Pages.SingleOrDefault(o=>Misc.MakeURL(o.Title) == URL);

and I'm getting this error:

The method 'MakeURL' is not supported

I'm using Subsonic 3. Any ideas would be great, thanks.

This is simply not possible,

subsonic translates your expression to SQL, so

Pages.SingleOrDefault(o => o.Title == "title");

will propably generate a similar query like this

SELECT * FROM pages WHERE title = 'title' LIMIT 1

and you are expecting subsonic to convert your MakeUrl(...) method into SQL. What do you expect?

SELECT * FROM pages WHERE MAKEURL(title) = 'title' LIMIT 1

However, you can either just query the title or call ToList() on your pages, but that will pull all records from the database.

Page = Pages.ToList().SingleOrDefault(o=>Misc.MakeURL(o.Title) == URL);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM