我想从我的种子文件中为我的用户对象播种“位置”数据
C# 对象,其中 Point 是 aNetTopologySuite.Geometries.Point
是我的用户对象的一部分
public class User: IdentityUser<int> {
// member data here
public Point Location { get; set; } // has lat/lng data points
}
我通过做这样的事情在启动时将数据播种到我的数据库
public void SeedUsers()
{
if (!_userManager.Users.Any())
{
var userData = System.IO.File.ReadAllText("Data/UserSeedData.json");
var users = JsonConvert.DeserializeObject<List<User>>(userData);
var roles = new List<Role>
{
new Role{Name = "Member"},
new Role{Name = "Admin"},
new Role{Name = "Moderator"},
new Role{Name = "VIP"},
};
foreach (var role in roles)
{
_roleManager.CreateAsync(role).Wait();
}
foreach (var user in users)
{
user.Photos.SingleOrDefault().IsApproved = true;
_userManager.CreateAsync(user, "password").Wait();
_userManager.AddToRoleAsync(user, "Member").Wait();
}
}
}
使用这样的 json 数组的 json 文件“UserSeedData.json”,我希望能够在其中粘贴某种代表 lng/lat 数据点的“位置”数据。
{
"Email": "myemailaddress@gmail.com",
"Username": "Lola",
"Gender": "female",
"DateOfBirth": "1994-02-21",
"Password": "password",
"Created": "2017-08-02",
"LastActive": "2017-08-02",
"Introduction": "blah blah blah",
"LookingFor": "blah blah blah",
"City": "San Francisco",
"Country": "United States",
"Longitude": -122.431297,
"Latitude": 37.773972,
"Location": // something here!!!
"Photos": [{
"url": "https://randomuser.me/api/portraits/women/3.jpg",
"isMain": true,
"description": "Non deserunt labore sunt ex laboris et adipisicing ullamco officia minim."
}]
}
现在我知道在我的种子方法中我可以做这样的事情,但我正在寻找一种方法将它包含在我的 .json 文件中,这样我就可以使用不同的数据点
foreach (var user in users)
{
user.Photos.SingleOrDefault().IsApproved = true;
user.Location = new Point(-122.4194155, 37.7749295) { SRID = 4326 };
_userManager.CreateAsync(user, "password").Wait();
_userManager.AddToRoleAsync(user, "Member").Wait();
}