IInsertDataSyntax Rows(IEnumerable)
See original GitHub issueThe idea is to turn this:
Insert.IntoTable("TableName")
.Row(new { SomeColumn = "test1" })
.Row(new { SomeColumn = "test2" });
into this:
Insert.IntoTable("TableName")
.Rows(new [] {
{ SomeColumn = "test1" },
{ SomeColumn = "test2" }
});
The actual use case? Piping CsvHelper GetRecords<T>() results directly into Insert.IntoTable("TableName").Rows(csvReader.GetRecords<T>()
[Migration(1)]
public class M1_MigrationTest : ForwardOnlyMigration
{
public void Up()
{
CsvHelper.Configuration.CsvConfiguration config = new CsvHelper.Configuration.CsvConfiguration();
config.RegisterClassMap<PersonRecordMap>();
using (var reader = new CsvHelper.CsvReader(
new System.IO.StreamReader(GetPersonDataAsEmbeddedResourceStream()),
config))
{
Insert.IntoTable("Person").Rows(reader.GetRecords<PersonRecordMap>().ToList());
}
}
private System.IO.Stream GetPersonDataAsEmbeddedResourceStream()
{
/* etc */
}
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
c# - How to add an item to an IEnumerable
IEnumerable is an interface. You can't use Add() on an IEnumerable because they're not required to implement an Add() method.
Read more >Enumerable.Append<TSource>(IEnumerable ...
A sequence of values. ... The value to append to source . Returns. IEnumerable<TSource>. A new sequence that ends with element . Exceptions....
Read more >Bulk insert data — ClosedXML 0.102.0 documentation
A method used to insert the values from a generic IEnumerable<> is the IXLCell.InsertData(IEnumerable data) , despite the parameter not being generic ...
Read more >EnumerableRowCollection<TRow> Class (System.Data)
Determines whether any element of a sequence satisfies a condition. Append<TSource>(IEnumerable<TSource>, TSource). Appends a value to the end of the sequence.
Read more >Bulk Copy (Bulk Insert)
Some database servers provide functionality to insert large amounts of data ... IEnumerable<T> source) BulkCopyRowsCopied BulkCopy<T>(this DataConnection ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Counter suggestion:
OK, ok, definitely not as nice as having:
IOW: I agree with this proposal.
Is it possible to use
System.ComponentModel.DataAnnotations.Schema.ColumnAttribute
? Or any other custom attribute with the same functionality will do.Currently
ExtractData(object)
uses the name of a property, but it might be possible that the name of a column differs from the property name.https://github.com/fluentmigrator/fluentmigrator/blob/9c87d698b161b3a1bb596a5624c02891a64459c5/src/FluentMigrator/Builders/Insert/InsertDataExpressionBuilder.cs#L74-L86
By the way, my implementation as an extension method: