Insert class with generic.
See original GitHub issueHey, I’m not sure if I’m doing something wrong but I am getting an error when trying to insert an object with generic type. Is this possible or am I doing something wrong?
LiteDB.LiteException: Invalid format: Channel`1
at LiteDB.CollectionService.Add(String name)
at LiteDB.LiteEngine.GetCollectionPage(String name, Boolean addIfNotExits)
at LiteDB.LiteEngine.Transaction[T](String collection, Boolean addIfNotExists, Func`2 action)
at LiteDB.LiteEngine.Insert(String collection, BsonDocument doc, BsonType autoId)
at LiteDB.LiteCollection`1.Insert(T document)
public class Channel<TUser>
{
public int ChannelId { get; set; }
public IList<TUser> Users { get; set; }
}
public class User
{
public int Userid { get; set; }
}
using(var db = new LiteRepository("config.db"))
{
var channel = new Channel<User>{ChannelId = 1, Users = new List<User>{new User{Userid = 1}}};
db.Insert(channel);
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:5
Top Results From Across the Web
java - Can I put a class in a generic class declaration?
No. Generics are evaluated at compile time, while the code would be run later at runtime.
Read more >Java Generics Example Tutorial - Generic Method, Class ...
Let's see how generics help us using collection classes safely. List list = new ArrayList(); list.add("abc"); list.add(new Integer(5)); //OK for ...
Read more >Generic Classes - C# Programming Guide
Typically, you create generic classes by starting with an existing concrete class, and changing types into type parameters one at a time ...
Read more >Generic Class in Java
A Generic class simply means that the items or functions in that class can be generalized with the parameter(example T) to specify that...
Read more >Generic Types - Learning the Java Language
A generic type is a generic class or interface that is parameterized over types. The following Box class will be modified to demonstrate...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
My best guess ist that you’d have to sepcify the collection name manually Because of https://github.com/mbdavid/LiteDB/blob/master/LiteDB/Mapper/BsonMapper.cs#L102 Try this: https://github.com/mbdavid/LiteDB/wiki/Object-Mapping
Hi! With the objective of organizing our issues, we are closing old unsolved issues. Please check the latest version of LiteDB and open a new issue if your problem/question/suggestion still applies. Thanks!