ServiceStack.OrmLite equivalent of Single/SingleOrDefault from Entity Framework

谁说我不能喝 提交于 2019-12-12 05:28:14

问题


Currently when using OrmLite library from ServiceStack if I want single entity selected I do:

AppUser user = db.First<AppUser>(q => q.Id == id);

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);

回答1:


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.OrmLite/commit/f2f5f80f150f27266bdcaf81b77ca60b62897719#diff-e9a84724e6a8315ec7f7fc5a5512a44b

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



来源:https://stackoverflow.com/questions/21462671/servicestack-ormlite-equivalent-of-single-singleordefault-from-entity-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!