mikependon / RepoDB

A hybrid ORM library for .NET.
Apache License 2.0
1.68k stars 122 forks source link

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

Open kampilan opened 3 years ago

kampilan commented 3 years ago

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

mikependon commented 3 years ago

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 commented 3 years ago

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.

kampilan commented 3 years ago

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 commented 3 years ago

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

mikependon commented 3 years ago

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. :)

kampilan commented 3 years ago

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

mikependon commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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