praeclarum / sqlite-net

Simple, powerful, cross-platform SQLite client and ORM for .NET
MIT License
4.03k stars 1.42k forks source link

Query with Where() returns no results, fails only with UWP release build #1235

Open mbae23 opened 3 months ago

mbae23 commented 3 months ago

With an UWP release build (with UseDotNetNativeToolchain = true), this code snippet returns null although there is a row with the given ID in the database. It works with an UWP debug build or on Android or iOS. (This runs inside a Xamarin app.)

       public ILeistung GetLeistung(LeistungId? id)
       {
           if (id == null)
           {
               return null;
           }

           var dbobj = _dbConn.Table<DbLeistung>().FirstOrDefault(l => l.Id == id.Value.Value);

           return dbobj == null ? null : CreateBOImplLeistung(dbobj);
       }

_dbConn is a SQLiteConnection, and LeistungId is just a wrapper for an int property called "Value".

After this change, it works:

       public ILeistung GetLeistung(LeistungId? id)
       {
           if (id == null)
           {
               return null;
           }

           var searchId = id.Value.Value;

           var dbobj = _dbConn.Table<DbLeistung>().FirstOrDefault(l => l.Id == searchId);

           return dbobj == null ? null : CreateBOImplLeistung(dbobj);
       }

Problem is, I'd have to change 20 methods or so with similar code. What is going on here? Maybe some optimization that goes wrong?