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.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user3266638
  • 429
  • 8
  • 25
  • 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. – devlin carnate Jul 06 '18 at 20:34
  • 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. – Gert Arnold Jul 08 '18 at 19:35
  • I recommend using these two good Nuget packages: https://www.nuget.org/packages/LumenWorksCsvReader/ to read CSV file and https://www.nuget.org/packages/Z.EntityFramework.Extensions/ to BulkInsert them into DB table. – Sergei Zinovyev Jul 07 '18 at 01:03

1 Answers1

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.
d.stack
  • 429
  • 3
  • 5