This file contains hidden or 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
| CreateTableDefinition<CoolColor,Guid>(c => c.Id) |
This file contains hidden or 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
| _serializers.Add(typeof (decimal), | |
| new Tuple<Action<BinaryWriter, object>, Func<BinaryReader, object>>( | |
| (bw, obj) => | |
| { | |
| var bits = decimal.GetBits((decimal) obj); | |
| bw.Write(bits[0]); | |
| bw.Write(bits[1]); | |
| bw.Write(bits[2]); | |
| bw.Write(bits[3]); | |
| }, |
This file contains hidden or 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
| public Action<object, object> Setter | |
| { | |
| get | |
| { | |
| if (_propertyInfo != null) | |
| { | |
| return (obj, prop) => _propertyInfo.GetSetMethod().Invoke(obj, new[] { prop }); | |
| } | |
| return (obj, prop) => _fieldInfo.SetValue(obj, prop); |
This file contains hidden or 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
| var isList = typeof(IList).IsAssignableFrom(type); | |
| var isDictionary = typeof(IDictionary).IsAssignableFrom(type); | |
| var isArray = typeof(Array).IsAssignableFrom(type); | |
| var noDerived = isList || isDictionary || isArray; | |
| // first fields | |
| var fields = from f in type.GetFields() | |
| where | |
| !f.IsStatic && |
This file contains hidden or 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
| public class Cat | |
| { | |
| public string Key { get; set; } | |
| public string Name { get; set; } | |
| } |
This file contains hidden or 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
| public class Combo | |
| { | |
| public int Id { get; set; } | |
| public CoolColor Color { get; set; } | |
| public Planet Planet { get; set; } | |
| public Cat Cat { get; set; } | |
| } |
This file contains hidden or 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
| protected override List<ITableDefinition> RegisterTables() | |
| { | |
| return new List<ITableDefinition> | |
| { | |
| CreateTableDefinition<Cat,string>(c => c.Key), | |
| CreateTableDefinition<CoolColor,Guid>(c => c.Id), | |
| CreateTableDefinition<Planet,int>(p => p.Id), | |
| CreateTableDefinition<Combo,int>(co => co.Id) | |
| }; | |
| } |
This file contains hidden or 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
| public static void PopulateDatabase(ISterlingDatabaseInstance db) | |
| { | |
| var colors = new [] { "Red", "Orange", "Yellow", "Blue", "Green", "Indigo", "Violet"}; | |
| var cats = new [] { "Panther", "Cougar", "Lynx", "Jaguar", "Leopard", "Cheetah", "Lion"}; | |
| var planets = new [] { "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto"}; | |
| var colorItemList = colors.Select(c => new CoolColor { Name = c }).ToList(); | |
| Console.WriteLine("Saving colors (doesn't really take a second, but we'll wait anyway)..."); | |
This file contains hidden or 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
| var combos = db.Query<Combo, int>() | |
| .Where(c => c.LazyValue.Value.Color.Id == colorList[idx].Id) // filter | |
| .Select(c => c.LazyValue.Value); // project to lazy-loaded value | |
| var comboList = combos.Select(c => $"{c.Color.Name} {c.Planet.Name} {c.Cat.Name}"); | |
| foreach(var combo in comboList.OrderBy(c => c)) | |
| { | |
| Console.WriteLine($"Found awesome combo {combo}."); | |
| } |
This file contains hidden or 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
| public class FoodItem | |
| { | |
| public string FoodId { get; set; } | |
| public string FoodGroupId { get; set; } | |
| public FoodGroup Group { get; set; } | |
| public string Description { get; set; } | |
| public string ShortDescription { get; set; } | |
| public string CommonNames { get; set; } | |
| public string Inedible { get; set; } | |
| public Weight[] Weights { get; set; } |