实体框架中与Single/SingleOrDefault等效的ServiceStack.OrmLite [英] ServiceStack.OrmLite equivalent of Single/SingleOrDefault from Entity Framework

查看:110
本文介绍了实体框架中与Single/SingleOrDefault等效的ServiceStack.OrmLite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前在使用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:

https://github.com/ServiceStack/ServiceStack. commit/f2f5f80f150f27266bdcaf81b77ca60b62897719#diff-e9a84724e6a8315ec7f7fc5a5512a44b

似乎我需要从代码中扩展该类.

Seems I'll need to extend that class from within my code.

这篇关于实体框架中与Single/SingleOrDefault等效的ServiceStack.OrmLite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆