I need to create SQL table with unknown sized array of strings, integers or whatever. Best way to do this is to create separate table for it. Like this (pseudo-code follows, I have no idea if I'm using "primary key" correctly):
public class DataBase : DataContext
{
public Table<UserAccount> users { get { return GetTable<UserAccount>(); } }
public Table<UserAccount_roles> userroles { get { return GetTable<UserAccount_roles>(); } }
}
[Table]
public class UserAccount
{
[Column(IsPrimaryKey = true)]
public string username;
[Column]
public string password;
}
[Table]
public class UserAccount_roles
{
[Column(IsPrimaryKey = true)]
public string userName;
[Column(IsPrimaryKey = true, IsDbGenerated = true)]
public int roleIdx;
[Column]
public int arrayValue;
}
However, this feels clumsy as UserAccount_roles could be just simple "List<> roles" inside UserAccount-class if I shouldn't be worrying of SQL-implementation.
I'd rather do something like this:
public class DataBase : DataContext
{
public Table<UserAccount> users { get { return GetTable<UserAccount>(); } }
}
[Table]
public class UserAccount
{
[Column(IsPrimaryKey = true)]
public string username;
[Column]
public string password;
[MyColumn]
public MySQLList<DataBase, int> roles;
}
I thought of doing "class MySQLList<B, T> : List<T>". In DataBase-class ("B") I have made some static methods to grant access to correct database. Then inside MySQLList I manipulate database by overloaded List<> -methods. This should result building and accessing table UserAccount_roles "under the hood", as programmer (mostly me) sees just simplified solution in form on customized List<>.
My actual questions are:
- I bet there are some ready implementations for this. Where I can find one?
- I think I am not able to do any "[table] class MyTable" -declarations in MySQLList<>. Do I have to do actual SQL-language coding there, or is there any way of creating Linq to SQL -class and attribute stuff during compilation / run-time?
- Any generic caveats at this approach?-)