0

There is a CSV file with a header that needs to be inserted into a database through a web app.

Is it possible to send the data to a stored procedure via Entity Framework? Or what is a better solution?

It has to be done through the web app and the table has an extra column which is just a unique id for each row.

3
  • 1
    Create a class that maps the columns & data types from the csv, write a method that imports the csv to the class and then call the stored procedure to save the data. Commented Jul 6, 2018 at 20:34
  • I recommend using these two good Nuget packages: nuget.org/packages/LumenWorksCsvReader to read CSV file and nuget.org/packages/Z.EntityFramework.Extensions to BulkInsert them into DB table. Commented Jul 7, 2018 at 1:03
  • Note that if it wasn't for the dupicates this question would have been closed as too broad (all the way from a not-specified CSV file through a not-specified stored procedure into a not-specified database schema) or opinion-based ("Or what is a better solution?"). This type of question just shouldn't be asked here. Commented Jul 8, 2018 at 19:35

1 Answer 1

0

Yes, data needed for stored procedure may be supplied via EF

If you just using SP as it's easier for you - better not. You will defeat EF benefit of keeping code control over data. In short everything external to EF stays external (e.g. virtual members data won't update automatically).

Specify unique ids in data map as auto-generated item, backed by db configuration.

As @delvin mentioned above map your data from csv into object, then work with object to push data to your data tables.

Few references to start with:

  1. General How-To
  2. Few ways to deal with auto-generated items.
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.