Skip to content

Instantly share code, notes, and snippets.

@ronnyek
Last active March 26, 2019 14:59
Show Gist options
  • Select an option

  • Save ronnyek/02170a7852d1dd9138bc4f7581039d88 to your computer and use it in GitHub Desktop.

Select an option

Save ronnyek/02170a7852d1dd9138bc4f7581039d88 to your computer and use it in GitHub Desktop.
So the idea is the table structure might look like this
Users
| Id | FirstName | LastName | Profile | Preferences |
-----------------------------------------------------------
| 10 | Bob | Jones |{ Field1:.. | [{key:... |
using LinqToDb;
namespace Demo {
public class Repository {
public UserWithProfile GetUserById(int id){
using (var db = GetDataContext(...))
{
return db.Users.FirstOrDefault(x=>x.Id == id);
}
}
}
}
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