Info
Version: | 2.0.5 |
Author(s): | Jim Deane |
Last Update: | Sunday, June 5, 2016 |
.NET Fiddle: | Create the first Fiddle |
Project Url: | https://github.com/jimdeane/SerializeEFTablesToString |
NuGet Url: | https://www.nuget.org/packages/SerializeEFTablesToString |
Install
Install-Package SerializeEFTablesToString
dotnet add package SerializeEFTablesToString
paket add SerializeEFTablesToString
SerializeEFTablesToString Download (Unzip the "nupkg" after downloading)
Dependencies
- EntityFramework(>= 6.1.3)
The utility Class can be used as follows:
string parameterString= $"Customers," + // Outputs all columns for all records in the Customer Table
$"Customers[]" + // same as above
$"Orders[OrderId;OrderQuantity]" + // outputs only the OrderId and
// OrderQuantity from all records in the Orders table
$"Payments[!PaymentId;Date]"; // Outputs columns EXCEPT PaymentId and Date from the Payments Table
SomeDbContext context = new SomeDbContext();
Formatter formatter = new Formatter();
String formattedOutputString = formatter.FormatEntities(context, parameterString);
The output string will have newline delimited lines as follows:
Customers
| CustomerId | Name | DateOfBirth |
| 1 | Jon Doe | 1982-03-12 |
| 2 | Eric Hand | 1966-04-15 |
Customers[]
| CustomerId | Name | DateOfBirth |
| 1 | Jon Doe | 1982-03-12 |
| 2 | Eric Hand | 1966-04-15 |
Orders[OrderId;OrderQuantity]
| OrderId | Quantity |
| 456 | 78 |
| 6578 | 65 |
Payments[!PaymentId;Date]
| PaymentAmount |
| 23.56 |
| 45.89 |
This last example assumes there were three columns ion the table two of which were excluded.
Note these are TABLE names not the Entity names as DbContext.Database.SqlQuery is used.