2024-07-19 17:08:37 +00:00
|
|
|
|
using System;
|
2024-07-19 20:00:13 +00:00
|
|
|
|
using System.Globalization;
|
2024-07-19 17:08:37 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2024-07-19 20:00:13 +00:00
|
|
|
|
using CsvHelper.Configuration;
|
|
|
|
|
using CsvHelper;
|
|
|
|
|
|
2024-07-19 17:08:37 +00:00
|
|
|
|
using net.nehmer.sa.model;
|
2024-07-19 20:00:13 +00:00
|
|
|
|
using System.Text;
|
2024-07-19 17:08:37 +00:00
|
|
|
|
|
|
|
|
|
using var db = new StarsDatabase("stars.sqlite");
|
|
|
|
|
|
|
|
|
|
db.Database.EnsureDeleted();
|
|
|
|
|
db.Database.EnsureCreated();
|
|
|
|
|
|
|
|
|
|
// Note: This sample requires the database to be created before running.
|
|
|
|
|
Console.WriteLine($"Database path: {db.DbPath}.");
|
|
|
|
|
|
2024-07-19 20:00:13 +00:00
|
|
|
|
var config = CsvConfiguration.FromAttributes<Planet>(CultureInfo.InvariantCulture);
|
|
|
|
|
config.Delimiter = "\t";
|
|
|
|
|
config.Escape = '\0';
|
|
|
|
|
config.MissingFieldFound = null;
|
|
|
|
|
|
|
|
|
|
using (var reader = new StreamReader("/home/torben/goingth/GOINGTH.p1", Encoding.Latin1))
|
|
|
|
|
using (var csv = new CsvReader(reader, config))
|
|
|
|
|
{
|
|
|
|
|
List<Planet> records = csv.GetRecords<Planet>().ToList();
|
|
|
|
|
foreach (Planet p in records)
|
|
|
|
|
{
|
|
|
|
|
db.Add(p);
|
|
|
|
|
}
|
|
|
|
|
db.SaveChanges();
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-19 17:08:37 +00:00
|
|
|
|
/*
|
|
|
|
|
// Create
|
|
|
|
|
Console.WriteLine("Inserting a new blog");
|
|
|
|
|
db.Add(new Blog { Url = "http://blogs.msdn.com/adonet" });
|
|
|
|
|
db.SaveChanges();
|
|
|
|
|
|
|
|
|
|
// Read
|
|
|
|
|
Console.WriteLine("Querying for a blog");
|
|
|
|
|
var blog = db.Blogs
|
|
|
|
|
.OrderBy(b => b.BlogId)
|
|
|
|
|
.First();
|
|
|
|
|
|
|
|
|
|
// Update
|
|
|
|
|
Console.WriteLine("Updating the blog and adding a post");
|
|
|
|
|
blog.Url = "https://devblogs.microsoft.com/dotnet";
|
|
|
|
|
blog.Posts.Add(
|
|
|
|
|
new Post { Title = "Hello World", Content = "I wrote an app using EF Core!" });
|
|
|
|
|
db.SaveChanges();
|
|
|
|
|
|
|
|
|
|
// Delete
|
|
|
|
|
// Console.WriteLine("Delete the blog");
|
|
|
|
|
// db.Remove(blog);
|
|
|
|
|
// db.SaveChanges();
|
|
|
|
|
*/
|