Created
May 5, 2020 08:03
-
-
Save dj-nitehawk/8bde0d63524f39b5faf2f6e314237f94 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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