question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Insert class with generic.

See original GitHub issue

Hey, 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:closed
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
PascalSenncommented, Apr 13, 2018

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

0reactions
lbnascimentocommented, Feb 28, 2020

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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found