Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9240845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:15:33+00:00 2026-06-18T08:15:33+00:00

Yesterday I found this great ORM and would like to perform some testings on

  • 0

Yesterday I found this great ORM and would like to perform some testings on more complex stuff than the samples provided on github.

This is the model I’m using

class BaseClass
{
    [AutoIncrement]
    public int Id { get; set; }

    [StringLength(200)]
    public string Name { get; set; }
}

[Alias("artist")]
class Artist : BaseClass
{

}

[Alias("genre")]
class Genre : BaseClass
{

}

[Alias("artistgenre")]
class ArtistGenre
{
    [PrimaryKey]
    public int Id { get; set; }

    [Alias("idgenre")]
    [References(typeof(Genre))]
    public int IdGenre { get; set; }

    [Alias("idartist")]
    [References(typeof(Artist))]
    public int IdArtist { get; set; }
}

And this is what I’m trying to achieve (although it doesn’t work since the Identity values are unknown when inserting into artistgenre table).

                if (dbConn.TableExists("artistgenre"))
                    dbConn.DropTable<ArtistGenre>();

                if (dbConn.TableExists("artist"))
                    dbConn.DropTable<Artist>();

                if (dbConn.TableExists("genre"))
                    dbConn.DropTable<Genre>();

                dbConn.CreateTables(false, typeof(Artist), typeof(Genre), typeof(ArtistGenre));

                var genres = new List<Genre>();
                genres.Add(new Genre() { Name = "Rock" });
                genres.Add(new Genre() { Name = "Pop" });
                genres.Add(new Genre() { Name = "Jazz" });
                genres.Add(new Genre() { Name = "Classic" });
                genres.Add(new Genre() { Name = "Bossanova" });

                var artists = new List<Artist>();
                artists.Add(new Artist() { Name = "Rush" });
                artists.Add(new Artist() { Name = "Queen" });
                artists.Add(new Artist() { Name = "Pat Metheny" });

                var ag = new List<ArtistGenre>();
                var a = artists.FirstOrDefault(c => c.Name == "Rush");
                var g = genres.FirstOrDefault(c => c.Name == "Rock");
                ag.Add(new ArtistGenre() { IdArtist = a.Id, IdGenre = g.Id });

                dbConn.SaveAll<Artist>(artists);
                dbConn.SaveAll<Genre>(genres);
                dbConn.SaveAll<ArtistGenre>(ag);

Is there a simple solution other than adding each row and obtaining its Identity values?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T08:15:34+00:00Added an answer on June 18, 2026 at 8:15 am

    OrmLite doesn’t currently populate the model with the auto-incrementing id atm. The way you obtain the autoincrement Id is to use db.GetLastInsertId() after each insert, e.g:

    artists.ForEach(artist => {
      db.Insert(artist);
      artist.Id = db.GetLastInsertId();
    });
    

    I recommend wrapping this in an extension method to make this nicer to work with.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I asked this question yesterday, but I wrote it far more complicated than I
I work on this issue since yesterday. More specifically - I have some values
Yesterday, I found myself writing code like this: SomeStruct getSomeStruct() { SomeStruct input; cin
Yesterday while going through this question, I found a curious case of passing and
I asked a question about different testing frameworks yesterday. This question can be found
Yesterday I ran into this: One of my :hover -states stopped working. I found
Found an interesting problem on SQL Server yesterday, try this: DECLARE @a REAL =
I found some struct initialization code yesterday that threw me for a loop. Here's
Yesterday I found something very strange (I think). It looks like Form.TransparencyKey gives different
Yesterday, I had some xdebug problems which people on this site very graciously helped

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.