C# Syntax for reading an entity from an external database in an extension method
Service Studio Version
11.11.0 (Build 42152)

Will someone please give me an example of reading an entity from a database table?  I have the following:


const string MY_SQL = "SELECT * FROM MyTable WHERE Attrib IS NULL";


DatabaseProvider dbProvider = DatabaseAccess.ForExternalDatabase("My DataBase");


// Use a user managed transaction

using (CommittableTransaction commitableTransaction = dbProvider.GetCommittableTransaction())

{

using (Command cmd = commitableTransaction.CreateCommand(MY_SQL))

{

using (IDataReader reader = cmd.ExecuteReader())

{

while (reader.Read())

{

ENMyTableEntityRecord entityRecord = new ENMyTableEntityRecord();

entityRecord.ReadDB(reader);

}

}

}

}

It seems to be choking when trying to read a boolean column from the database.  This is just a guess as to how this might work, so this may be totally off.  Can you use select * and still use the ReadDB method, or do you have to select the columns explicitly in the order that the ReadDB method expects them?

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.