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 89877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:47:08+00:00 2026-05-10T22:47:08+00:00

I am not sure if I am missing something grotesquely obvious or what, but

  • 0

I am not sure if I am missing something grotesquely obvious or what, but I can’t seem to figure out how to efficiently access tables in a relational database. I am using PostgreSQL for the database server (and Npgsql for its access) and C# with Mono 2.0.

Say I have the table created by the following CREATE TABLE and INSERT statements.

CREATE TABLE foo (   id UUID NOT NULL PRIMARY KEY,   bar VARCHAR(20) NOT NULL,   baz INT NOT NULL )  INSERT INTO foo VALUES ('f42d3178-b900-11dd-ac23-001966607b2e', 'foo!', 1); 

The way I understand it thus far, I have to (C#):

using(NpgsqlConnection dbc = new NpgsqlConnection(connectionString)) {   using(NpgsqlCommand cmd = new NpgsqlCommand('SELECT * FROM foo LIMIT 1', dbc)) {     NpgsqlDataReader rdr = cmd.ExecuteReader();      if(!rdr.HasRows())       throw new Exception('No rows');      rdr.Read();      Guid id = rdr.GetGuid(0);     string bar = rdr.GetString(1);     int baz = rdr.GetString(2);   } } 

But, what I would really like to do is something like the following pseudocode:

using(NpgsqlConnection dbc = new NpgsqlConnection(connectionString)) {   using(NpgsqlCommand cmd = new NpgsqlCommand('SELECT * FROM foo LIMIT 1', dbc)) {     NpgsqlDataReader rdr = cmd.ExecuteReader();      if(!rdr.HasRows())       throw new Exception('No rows');      rdr.Read();      Guid id = (Guid)rdr['id'];     string bar = (string)rdr['bar'];     int baz = (int)rdr['baz'];   } } 

It doesn’t seem to me (and hopefully I am just missing something obvious somewhere) that the top method of database access is required, and that really is cumbersome when you are going to be working with lots of relations… so, is there a way to do something closer to the latter pseudocode?

  • 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. 2026-05-10T22:47:08+00:00Added an answer on May 10, 2026 at 10:47 pm

    If you want easy go with an ORM framework.

    If you want max performance this should work. Just remember caching is alwast fastest 🙂

    Top example is also faster because there is no conversion.

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

Sidebar

Related Questions

I am not sure whether I am missing something basic. But I am unable
Not sure if the title is quite right for the question but I can't
Not sure whether I am missing something. When making an actor remote, the main
before posting the whole code, i wanted to make sure I am not missing
Not sure how to ask a followup on SO, but this is in reference
Not sure what exactly is going on here, but seems like in .NET 1.1
Not sure if anyone listened to Hanselminutes episodes 134 and 135, but at the
Not sure if this is possible or if I'm expressing correctly what I'm looking
Not sure if this is intended behavior or a bug or a wrong function
Not sure what's going on here. I have a DateTime object, and when I

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.