![]() undertakingsToAdd is enumerable of normal entity records, which I want to bulkInsert into DB. ![]() I showed an example with transaction, but it can also be done with normal connection retrieved from context. ![]() UndertakingHelper.SaveAll( as Npgsql.NpgsqlConnection, undertakingsToAdd)) I use it the following way (I had entity named Undertaking): var undertakingHelper = BulkMapper.CreateHelper("dbo", nameof(Model.Undertaking)) Helper = helper.MapUUID("\"" prop.Name "\"", x => (Guid)typeof(T).GetProperty(prop.Name).GetValue(x, null)) Helper = helper.MapReal("\"" prop.Name "\"", x => (float?)typeof(T).GetProperty(prop.Name).GetValue(x, null)) Ĭase Type guidType when guidType = typeof(Guid): Helper = helper.MapDouble("\"" prop.Name "\"", x => (double?)typeof(T).GetProperty(prop.Name).GetValue(x, null)) Ĭase Type floatType when floatType = typeof(float) || floatType = typeof(float?): Helper = helper.MapMoney("\"" prop.Name "\"", x => (decimal?)typeof(T).GetProperty(prop.Name).GetValue(x, null)) Ĭase Type doubleType when doubleType = typeof(double) || doubleType = typeof(double?): Helper = helper.MapTimeStamp("\"" prop.Name "\"", x => (DateTime?)typeof(T).GetProperty(prop.Name).GetValue(x, null)) Ĭase Type decimalType when decimalType = typeof(decimal) || decimalType = typeof(decimal?): Helper = helper.MapText("\"" prop.Name "\"", x => (string)typeof(T).GetProperty(prop.Name).GetValue(x, null)) Ĭase Type dateType when dateType = typeof(DateTime) || dateType = typeof(DateTime?): Helper = helper.MapInteger("\"" prop.Name "\"", x => (int?)typeof(T).GetProperty(prop.Name).GetValue(x, null)) Ĭase Type stringType when stringType = typeof(string): If (Attribute.IsDefined(prop, typeof(KeyAttribute)))Ĭase Type intType when intType = typeof(int) || intType = typeof(int?): Var properties = typeof(T).GetProperties() Var helper = new PostgreSQLCopyHelper(schemaName, "\"" tableName "\"") I have written a small mapper, which auto mapped properties the way Entity Framework does: public static PostgreSQLCopyHelper CreateHelper(string schemaName, string tableName) I haven't found any proper free library to do so on this DB. I wanted to use effective bulkinsert, what turned out to be pretty difficult. I have recently run into similar problem, but we were using Postgresql. We can now see that the table has been updated.Probably you can check my other answer in which I describe a little helper I have created for this problem, making use of another helper really easy: Now we can use generic sql to update the data. ![]() Change the source to your CSV connection table and click Next.Ĭheck that the mapping is existing and click next, next again on the transfer settings and then click Finish to start the import. Now we can import the stage data for our update, right-click your stage table, click Import Data, select Table and click Next. Copy the create statement, change the table name, and execute. You can right-click your PostgreSQL table, click Generate SQL and then click DDL. We’ll need to create a staging table to perform our updates from using the csv data. Our csv file data looks like this: Create Staging Table The data in the current PostgreSQL table looks like this: Each csv file in your folder will be set up as a table with columns. You will now see a new connection this connection is set up exactly like a regular connection. The connection will load ALL csv files in that folder. You’re selecting a folder here, not a file. Click Next.Ĭlick Browse… and select the folder where your csv file is that you saved from Excel. Make sure the All tab is select on the left and scroll down to CSV. Right-click your database connection (or anywhere if your connections are empty), click Create and then click Connection. This time I will show you how to update data using a csv file inside DBeaver. ![]() If you’re not familiar with importing data using DBeaver, then I encourage you to view my previous blog here: ![]()
0 Comments
Leave a Reply. |