Last active
March 26, 2019 14:59
-
-
Save ronnyek/02170a7852d1dd9138bc4f7581039d88 to your computer and use it in GitHub Desktop.
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
| So the idea is the table structure might look like this | |
| Users | |
| | Id | FirstName | LastName | Profile | Preferences | | |
| ----------------------------------------------------------- | |
| | 10 | Bob | Jones |{ Field1:.. | [{key:... | |
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
| using LinqToDb; | |
| namespace Demo { | |
| public class Repository { | |
| public UserWithProfile GetUserById(int id){ | |
| using (var db = GetDataContext(...)) | |
| { | |
| return db.Users.FirstOrDefault(x=>x.Id == 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
| namespace Demo { | |
| public class UserProfile { | |
| public string Field1 {get;set;} | |
| public int Age {get;set;} | |
| } | |
| public class Preference { | |
| public string Key {get;set} | |
| public string Value {get;set;} | |
| public int Priority {get;set;} | |
| } | |
| [Table(Name = "Users")] | |
| public class UserWithProfile { | |
| [Identity, PrimaryKey] | |
| public int Id {get;set; | |
| [Column] | |
| public string FirstName {get;set;} | |
| [Column] | |
| public string LastName {get;set;} | |
| [Column("profile"), JsonSerialize] // some attribute / annotation to signify serialization | |
| public UserProfile Profile {get;set;} | |
| [Column("preferences"), JsonSerialize] | |
| public List<Preference> Preferences {get;set;} | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment