RepoDB icon indicating copy to clipboard operation
RepoDB copied to clipboard

Question: Documentation refers to fields parameter for Update, but it does not appear to actually exist

Open kampilan opened this issue 5 years ago • 9 comments

I'm new to RepoDB. So far looks very good. An absolute requirement for me is to be able to only update properties I actually changed on the client side. The documentation for Update refers to a fields parameter that should fit the bill. However in the actual code this parameter does not exist. If I Query a single entity change one property and call update all columns are updated from the properties whether they were modified or not. Very bad. How can I control what columns are written during an update?

Couple of observations from a noob:

  1. I'm using MySqlConnector. I did not realize I needed to call Bootstrap.Initiaize(). The exception thrown was NullReferenceException. It probably should be something more descriptive like "Did you forget to call Bootstrap?". No second chance for a good first impression kind of thing.

  2. Add Single and SingleOrDefault instead if Query(...).SingleOrDefault(). Cumbersome especially with async.

Thanks for all the hard work you must have put into this. Very promising!!! Jim

kampilan avatar Sep 19 '20 14:09 kampilan

Complete support to the fields argument is new to RepoDB. You have to use the latest beta release (RepoDb v1.12.0-beta4 and RepoDb.MySqlConnector v1.1.0-beta2). Noted on the other recommendation like FirstOrDefault or SingleOrDefault way of querying data.

mikependon avatar Sep 19 '20 14:09 mikependon

We are throwing a customized readable exception message if the bootstrapper has not been initialized. Such error message forwards you to the Getting Started tutorial, if that does not happened in your side, it is highly appreciated if you can include the Stacktrace.

mikependon avatar Sep 19 '20 14:09 mikependon

Thanks for the quick reply!!! I just figured that out. Sorry about that. No indication in the docs that it was a beta feature.

Jim

kampilan avatar Sep 19 '20 14:09 kampilan

I will try and recreate the exception I was getting earlier. Thanks

kampilan avatar Sep 19 '20 14:09 kampilan

Glad you find it and hopefully made it work. Do not forget to play around with the FieldCache.Get<T>() method and eliminate the unchanged fields from the results. Thanks for the kinds words BTW. :)

mikependon avatar Sep 19 '20 14:09 mikependon

Here is the stack trace you requested:

BTW the beta worked perfect regarding the fields parameter. Onward.

System.NullReferenceException : Object reference not set to an instance of an object. at RepoDb.DbFieldCache.GetInternalAsync[TDbConnection](TDbConnection connection, String tableName, IDbTransaction transaction, Boolean enableValidation) at RepoDb.DbConnectionExtension.QueryAllAsyncInternal[TEntity](IDbConnection connection, String tableName, IEnumerable1 fields, IEnumerable1 orderBy, String hints, String cacheKey, Nullable1 cacheItemExpiration, Nullable1 commandTimeout, IDbTransaction transaction, ICache cache, ITrace trace, IStatementBuilder statementBuilder) at RepoDb.Research.MicroTests.Test0001_0100_QueryDynamic() in F:\research\repodb\RepoDb.Research\MicroTests.cs:line 74 at NUnit.Framework.Internal.TaskAwaitAdapter.GenericAdapter1.BlockUntilCompleted() at NUnit.Framework.Internal.MessagePumpStrategy.NoMessagePumpStrategy.WaitForCompletion(AwaitAdapter awaitable) at NUnit.Framework.Internal.AsyncToSyncAdapter.Await(Func1 invoke) at NUnit.Framework.Internal.Commands.TestMethodCommand.RunTestMethod(TestExecutionContext context) at NUnit.Framework.Internal.Commands.TestMethodCommand.Execute(TestExecutionContext context) at NUnit.Framework.Internal.Execution.SimpleWorkItem.PerformWork()

kampilan avatar Sep 19 '20 14:09 kampilan

Is not this error are you getting? Below is the resultset when calling the non-sync method.

image

And below is for the async method.

image

mikependon avatar Sep 20 '20 12:09 mikependon

Please take note that it is working after I had added the call to the bootstrapper. I am using the version RepoDb.MySqlConnector v1.1.0-beta2.

mikependon avatar Sep 20 '20 12:09 mikependon

Can you create a dedicated issue (User Story) for the QueryFirstOrDefault() and/or QuerySingleOrDefault()? Thanks

mikependon avatar Sep 20 '20 12:09 mikependon