Skip to content

Instantly share code, notes, and snippets.

@dj-nitehawk

dj-nitehawk/Program.cs Secret

Created May 5, 2020
Embed
What would you like to do?
using MongoDB.Entities;
using MongoDB.Entities.Core;
using System.Collections.Generic;
using System.Linq;
namespace TestApp
{
public class Zone : Entity
{
public int SqlId { get; set; }
}
public class Search : Entity
{
public Many<Zone> Zones { get; set; }
public Search() => this.InitOneToMany(() => Zones);
}
public class _001_seed_zone_data : IMigration
{
public void Upgrade()
{
var zones = new List<Zone>();
for (int i = 1; i <= 20; i++)
{
zones.Add(new Zone { SqlId = i });
}
zones.Save();
}
}
public static class Program
{
private static void Main()
{
new DB("test", "127.0.0.1");
DB.Migrate();
var wantedZones = new[] { 1, 2, 3 };
var foundZones = DB.Find<Zone>()
.Many(z => wantedZones.Contains(z.SqlId));
var seach1Zones = foundZones.Where(z => new[] { 1, 2 }.Contains(z.SqlId));
var search2Zones = foundZones.Where(z => new[] { 1, 2, 3 }.Contains(z.SqlId));
var search1 = new Search();
var search2 = new Search();
DB.Save(new[] { search1, search2 });
search1.Zones.Add(seach1Zones);
search2.Zones.Add(search2Zones);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.