实体框架中与Single/SingleOrDefault等效的ServiceStack.OrmLite [英] ServiceStack.OrmLite equivalent of Single/SingleOrDefault from Entity Framework
问题描述
当前在使用ServiceStack中的OrmLite库时,如果我希望选择单个实体,我会这样做:
Currently when using OrmLite library from ServiceStack if I want single entity selected I do:
AppUser user = db.First<AppUser>(q => q.Id == id);
但是,由于Single更精确(显然,如果不知何故多个具有相同id的用户最终出现在数据库中,我会抛出异常),我想知道是否可以使用重载.目前,当我执行db.Single时,我只是通过手动过滤来获得该重载:
However since Single is more precise (obviously I want exception thrown if somehow multiple users with same id ended up in database) I was wondering if there is overload that I can use. Currently when I do db.Single I just get that overload with manual filtering:
public static T SingleOrDefault<T>(this IDbConnection dbConn, string filter);
推荐答案
好的,我发现了问题所在-我正在使用的版本(3.9.71)没有重载-稍后添加:
OK, I found what the issue is - the version I'm using (3.9.71) doesn't have that overload - it was added later:
似乎我需要从代码中扩展该类.
Seems I'll need to extend that class from within my code.
这篇关于实体框架中与Single/SingleOrDefault等效的ServiceStack.OrmLite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!