Can’t auto-generate IDENTITY with AddRange in Entity Framework

What was causing the problem? Enumerables! Take a look at the EDIT section in my question for the solution. EDIT: posting the updated code here as answer. The problem was in the way I used enumerables. Bottom line is you should never trust lazy loading when you need consistent results right away. public class Request … Read more

`Type.GetProperties` property order

The order simply isn’t guaranteed; whatever happens…. Happens. Obvious cases where it could change: anything that implements ICustomTypeDescriptor anything with a TypeDescriptionProvider But a more subtle case: partial classes. If a class is split over multiple files, the order of their usage is not defined at all. See Is the “textual order” across partial classes … Read more

What actually happens when using async/await inside a LINQ statement?

I recommend that you not think of this as “using async within LINQ”. Keep in mind what’s in-between the two: delegates. Several LINQ operators take delegates, and async can be used to create an asynchronous delegate. So, when you have an asynchronous method BazAsync that returns a Task: Task BazAsync(TBar bar); then this code results … Read more

How to mock IOptionsSnapshot instance for testing

You should be able to mock up the interface and create an instance of the options class for the test. As I am unaware of the nested classes for the options class I am making a broad assumption. Documentation: IOptionsSnapshot //Arrange //Instantiate options and nested classes //making assumptions here about nested types var options = … Read more

What is the preferred naming convention for Func method parameters?

There are precedents for using a noun in the Framework, e.g. Enumerable.Average<TSource>(this IEnumerable<TSource> source, Func<TSource, decimal?> selector) Enumerable.Count<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) Enumerable.GroupBy<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector) ConcurrentDictionary<TKey,TValue>.GetOrAdd(TKey key, Func<TKey, TValue> valueFactory); The noun is often an appropriate verb with an agentive suffix. In your example I would … Read more

Are there any benefits of reading each field async from a SqlDataReader?

After some peeking at reflector, the interesting methods here (GetFieldValueAsync<T>, IsDBNullAsync, and the internal method GetBytesAsync) only do “interesting” code for the CommandBehavior.SequentialAccess scenario. So: if you’re not using that: don’t bother – the row data is already buffered in memory, and Task<T> is pure overhead (although it will at least be an already-completed task … Read more

Set EventCallback outside of a Blazor component?

Turns out you can assign an event callback from C# code like this: this.ProgressManager.UpdateNotification = new EventCallback(this, (Action)Refresh); void Refresh() {} It also works with async methods, e.g.: this.ProgressManager.UpdateNotification = new EventCallback(this, (Func<ValueTask>)RefreshAsync); ValueTask RefreshAsync() {} UPDATE You can also use EventCallbackFactory to more conveniently create event callback objects, e.g.: new EventCallbackFactory().Create(this, Refresh)

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)