Comments (5)
Hello @boginw
It seems that your table doesn't have any identity column(s) which are generated by the database on insert.
Since the query is formed with those columns in mind (you can check it out here the code https://github.com/andreisabau/EFBulkInsert/blob/master/EFBulkInsert/BulkInsertExtension.cs#L100), the generatedColumnNames variable is empty and the query is ending in ",".
I should definitely add support for tables without any db generated columns.
In the meanwhile you could try to add/make a column as an identity, let me know if that works.
from efbulkinsert.
Hi @andreisabau
I'm quite new to MSSQL and Entity Framework. Is it correct that identity column(s) are primary keys? If so, I have composite keys added like such HasKey(ci => new { ci.CatalogueId, ci.LineId });
. Is this what you mean by Identity column(s)?
from efbulkinsert.
@boginw identity columns are different than primary keys.
You can read more here: https://dba.stackexchange.com/questions/46373/is-it-recommended-to-use-identity-as-an-alternative-to-primary-key or https://stackoverflow.com/questions/4293426/whats-the-difference-between-a-primary-key-and-identity - these explanations are better than what I could give.
What your table is missing (for EFBulkInsert to work in this version) is a column marked as an identity which basically auto increments the column's value on every INSERT.
From my knowledge the HasKey method makes the column as an identity only if it's used for a single key, not a composite one.
You can make other columns (int or bigint) as identity columns using the HasDatabaseGeneratedOption method or DatabaseGenerated attribute.
Property(x => x.ColumnName).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
// OR
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int ColumnName { get; set;}
I will also change EFBulkInsert to support tables without identity columns in a new version.
from efbulkinsert.
I followed your instructions, and got a bit further. The bad news is that it still wont run. I've added an identity column like you suggested. I'm now getting an System.Data.SqlClient.SqlException
exception with the message Invalid object name 'CatalogueLineItem'
, which is understandable, since no table is called that. Instead the table is called CatalogueLineItems
. Is there any way to specify the table name, or something similar?
from efbulkinsert.
Fixed in the latest version available at https://www.nuget.org/packages/EFBulkInsert/0.3.0
from efbulkinsert.
Related Issues (8)
- SqlBulkCopy fails when running inside an existing transaction
- .NET Framework 4.8 Not compatible
- Does not pluralize table names HOT 1
- SQL Exception Invalid Column Name HOT 2
- Related Entities HOT 1
- BulkInsert throws timeout exception and it's not configurable option HOT 1
- Isssue "Key Not Found in Dictionnary"
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from efbulkinsert.