GithubHelp home page GithubHelp logo

Comments (5)

andreisabau avatar andreisabau commented on September 25, 2024

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.

boginw avatar boginw commented on September 25, 2024

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.

andreisabau avatar andreisabau commented on September 25, 2024

@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.

boginw avatar boginw commented on September 25, 2024

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.

andreisabau avatar andreisabau commented on September 25, 2024

Fixed in the latest version available at https://www.nuget.org/packages/EFBulkInsert/0.3.0

from efbulkinsert.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.