Id by another class
See original GitHub issueDear LiteDB team
I am trying to create, like mentioned in this comment, a new class for my Id.
public class Target
{
[BsonId]
public EntityId Id { get; set; }
public string Name { get; set; }
}
public class EntityId
{
public EntityId()
{
}
[BsonId]
public int Id { get; set; }
}
static void Main(string[] args)
{
using (var db = new LiteDatabase(@"t.db"))
{
var col = db.GetCollection<Target>("t");
col.Insert(new Target { Name = "t" });
}
}
I get the next exception in versions 4.x:
Invalid BSON data type ‘Null’ on field ‘_id’.
I get the next exception in versions 5.x:
Unable to cast object of type ‘LiteDB.ObjectId’ to type ‘Mongo.EntityId’.
Many thanks for help. Many thanks for your feature.
Yaniv
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
Top Results From Across the Web
how to access an id from one class in another class
There are a couple of ways of solving this problem. One of the solution is as follow: py file. Rename method main() in...
Read more >how to access one class id in another class
Model): id in another class class site_survey_cancellation(models.TransientModel): code is below class site_survey(models.Model): _name = 'site.survey' name ...
Read more >constructor - Cannot call class from within another class
I have two classes. Inside class B, I want to use the method written in the class A. And I dont know why...
Read more >[Solved] How to access another class variable in different ...
In main, you set a vlaue to the ID property of the A instance, in B.getvale you don't. Because they are separate instances,...
Read more >Lesson 1: Understanding ID and Class in CSS
You assign an id attribute to an HTML element when: You want to stylize that element differently than other elements of the same...
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
@Yaniv-Y You would have to come up with a manual solution for your use case. LiteDB uses skip lists for indexing (and the
_id
field is always indexed), socol.Max()
should run on average in O(log n) - the worst case is O(n), but this should be very rare.I meant weather is there a way in code to generate the Id, which is
EntityId.Id
in my case. Because when I need to manually edit my composite primary key (EntityId
object) I need also to generate this int value. Hope was clear 😁EDIT:
Does col.Max() run in O(1) time?