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.

Id by another class

See original GitHub issue

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

github_iconTop GitHub Comments

1reaction
lbnascimentocommented, Jul 2, 2020

@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), so col.Max() should run on average in O(log n) - the worst case is O(n), but this should be very rare.

0reactions
Yaniv-Ycommented, Jul 2, 2020

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?

Read more comments on GitHub >

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

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