How to import records file in asp.net mvc with entity framework [closed]

1

I would like to ask a question and I do not know how to structure my need ..

I need to import / export a file with records, and depending on each record will be from a different table with their references and etc. What file formats is right? .csv, xls, and so on.

In the file do I separate each item with a delimiter or with a specific header for each item? What better way?

What is the best way to create this file layout and import / export? For now I have no idea how to do it.

    
asked by anonymous 17.11.2017 / 19:07

1 answer

0

You can use filehelpers .

See some examples of how to use it

Comma delimited data

1732,Juan Perez,435.00,11-05-2002
554,Pedro Gomez,12342.30,06-02-2004
112,Ramiro Politti,0.00,01-02-2000
924,Pablo Ramirez,3321.30,24-11-2002

Mapping class

using FileHelpers;

[DelimitedRecord(",")]
public class Customer
{
    public int CustId;

    public string Name;

    public decimal Balance;

    [FieldConverter(ConverterKind.Date, "dd-MM-yyyy")]
    public DateTime AddedDate;

}

Reading and writing with FileHelpers

var engine = new FileHelperEngine<Customer>();

// To Read Use:
var result = engine.ReadFile("FileIn.txt");
// result is now an array of Customer

// To Write Use:
engine.WriteFile("FileOut.txt", result);

Displaying the result

foreach (Customer cust in result)
{
    Console.WriteLine("Customer Info:");
    Console.WriteLine(cust.Name + " - " +
                      cust.AddedDate.ToString("dd/MM/yy"));
}

If I'm not mistaken, the newer version already supports properties as well.

    
17.11.2017 / 19:15