c#

“Specified type is not registered” error when bulk inserting table with geospatial data types

与世无争的帅哥 提交于 2021-02-20 17:56:41
问题 I'm trying to use the SqlBulkCopy class from the System.Data assembly (4.6.1) to bulk insert a table with a geospatial data type, using code that looks roughly like this (adapted from https://github.com/MikaelEliasson/EntityFramework.Utilities): public void InsertItems<T>(IEnumerable<T> items, string schema, string tableName, IList<ColumnMapping> properties, DbConnection storeConnection, int? batchSize) { using (var reader = new EFDataReader<T>(items, properties)) { var con = (SqlConnection

“Specified type is not registered” error when bulk inserting table with geospatial data types

*爱你&永不变心* 提交于 2021-02-20 17:56:04
问题 I'm trying to use the SqlBulkCopy class from the System.Data assembly (4.6.1) to bulk insert a table with a geospatial data type, using code that looks roughly like this (adapted from https://github.com/MikaelEliasson/EntityFramework.Utilities): public void InsertItems<T>(IEnumerable<T> items, string schema, string tableName, IList<ColumnMapping> properties, DbConnection storeConnection, int? batchSize) { using (var reader = new EFDataReader<T>(items, properties)) { var con = (SqlConnection

How to cast one compound custom type to another

痴心易碎 提交于 2021-02-20 17:04:11
问题 I'm trying to write a converter class for custom types--converting one type (and all of its properties) to another type that has matching properties. The problem comes in when the property is also a custom type, rather that a simple type. The custom types are all identical, except they live in different namespaces in the same solution. TypeTwo objects are Webservice references. For example public TypeOne ConvertToTypeTwo (TypeTwo typeTwo) { var typeOne = new TypeOne(); typeOne.property1 =

In C#, why is a variable not definitely assigned at the beginning of a finally block?

旧街凉风 提交于 2021-02-20 16:58:52
问题 I don't understand why the following code produces an error. Normally I can figure things out from the language specification, but in this case I don't understand the language specification. This isn't causing problems in my code, by the way, I just want to understand the language. Example: bool success; try { success = true; } catch { success = false; } finally { Console.WriteLine(success); // ERROR: Local variable 'success' might not be initialized before accessing } This behavior appears

Parsing TimeSpan from string including format

五迷三道 提交于 2021-02-20 15:01:47
问题 I'm sure this must be simple, but I can't figure out how to word it correctly in Google... I have a config which has a field: TimeToPoll="1d" Now I want to do something like : TimeSpan.Parse(TimeToPoll); Returning a timespan of one day. In C# EDIT: I'm looking for a method which allows parse of "1d" as well as "1s" or "1y" etc. Is this possible? Meaning: "1d" parses to {1.00:00:00} "1h" parses to {0.01:00:00} "1m" parses to {0.00:01:00} "1s" parses to {0.00:00:01} 回答1: The d is not needed and

Parsing TimeSpan from string including format

℡╲_俬逩灬. 提交于 2021-02-20 14:56:03
问题 I'm sure this must be simple, but I can't figure out how to word it correctly in Google... I have a config which has a field: TimeToPoll="1d" Now I want to do something like : TimeSpan.Parse(TimeToPoll); Returning a timespan of one day. In C# EDIT: I'm looking for a method which allows parse of "1d" as well as "1s" or "1y" etc. Is this possible? Meaning: "1d" parses to {1.00:00:00} "1h" parses to {0.01:00:00} "1m" parses to {0.00:01:00} "1s" parses to {0.00:00:01} 回答1: The d is not needed and

Xamarin Async method usage OnStart()

北慕城南 提交于 2021-02-20 14:50:33
问题 Is it considered a good practice to call an Async method that does some heavy lifting with server connections and data exchange during OnStart() event of the application given that this method does not touch the UI thread? Are all the components of the application properly initialized at the time of this event firing for the Async method to be able to execute? protected override async void OnStart() { sendHttpRequestAsync(); } private async void sendHttpRequestAsync() { await ... } 回答1: Avoid

Using EF Core HasQueryFilter on navigation properties

℡╲_俬逩灬. 提交于 2021-02-20 13:52:57
问题 I'm trying to apply a filter to my queries for multi-tenancy but it doesn't allow me to apply the filter when the property is part of a navigation property: modelBuilder.Entity<Level>().HasQueryFilter(lvl => lvl.SchoolYear.TenantId == _tenantProvider.TenantId); Here, Level is the property I want filtered but the property to use for filtering which is TenantId is is inside Level.SchoolYear. If its a top-level property it works fine. How can I apply a global filter when the property I need for

Static variable order [duplicate]

僤鯓⒐⒋嵵緔 提交于 2021-02-20 13:32:23
问题 This question already has answers here : Static field initialization order (C#) - can someone explain this snippet? (6 answers) Closed 7 years ago . I have aproblem with the order of static variable declaration in C# When i run this code: static class Program { private static int v1 = 15; private static int v2 = v1; static void Main(string[] args) { Console.WriteLine("v2 = "+v2); } } The output is: v2=15 But when i change the static variable declaration order like this: static class Program {

RX - rethrow an error in containing method

泄露秘密 提交于 2021-02-20 10:31:43
问题 I need to translate an error in an RX stream ( IObservable ) into an exception in the method that contains the subscription to the stream (because of this issue https://github.com/aspnet/SignalR/pull/1331 , Whereby errors arent serialised to clients.) Once this issue is fixed I will revert to handling error properly e.g. I have the following method public IObservable<StreamItem> LiveStream() { _mySvc.Start(); return _mySvc.ThingChanged(); } So I have tried to subscribe to the stream and