Db.Single<DB_CustomSetting> exception  Topic is solved

Discussions relating to the REST API of Jiwa 7.

Db.Single<DB_CustomSetting> exception

Postby neil.interactit » Thu Jul 06, 2023 5:26 pm

Hey guys,

I just hit a minor snafu - I'm sure I'll work around it, but thought you may like to know.

Calling the ServiceStack.OrmLite
Code: Select all
Db.Single<DB_CustomSetting>()

Causes the following exception:
Code: Select all
Invalid column name 'SY_Plugin'.
Invalid column name 'DB_CustomSettingValues'.

Some investigation shows that:
Code: Select all
public class DB_CustomSetting
{
   ...
   public virtual SY_Plugin SY_Plugin { get; set; }
   public virtual ICollection<JiwaFinancials.Jiwa.JiwaApplication.DB_CustomSettingValues> DB_CustomSettingValues { get; set; }
}
are not fields in the DB_CustomSetting table.

It seems that:
Code: Select all
public class DB_CustomSetting
{
   ...
   [IgnoreDataMember]public virtual SY_Plugin SY_Plugin { get; set; }
   [IgnoreDataMember]public virtual ICollection<JiwaFinancials.Jiwa.JiwaApplication.DB_CustomSettingValues> DB_CustomSettingValues { get; set; }
}
would resolve this.

I am guessing this could be a cross cutting issue across many entities.

Cheers,
Neil.
neil.interactit
Kohai
Kohai
 
Posts: 227
Joined: Wed Dec 03, 2014 2:36 pm
Topics Solved: 6

Re: Db.Single<DB_CustomSetting> exception

Postby neil.interactit » Thu Jul 06, 2023 5:56 pm

Just BTW, as an interim workaround, in case it helps anyone else ...

My code (with the exception) was:
Code: Select all
            var dbCustomSettingRec = Db.Single<DB_CustomSetting>(x => x.SettingName == "ProviderId");
            if (dbCustomSettingRec != null)
            {
                var acIdSettingId = dbCustomSettingRec.SettingID;

As I essentially only needed as scalar return (SettingID), I have simplified (and worked around) to:
Code: Select all
            var acIdSettingId = Db.ScalarSingle<string, DB_CustomSetting>(where => where.SettingName == "ProviderId", select => select.SettingID);
            if (acIdSettingId != null)
            {

By adding this little extension:
Code: Select all
    public static class JiwaExtensions
    {
        public static TResult ScalarSingle<TResult, TEntity>(this IDbConnection db, Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, object>> selectExpression)
        {
            return db.Scalar<TResult>(db.From<TEntity>().Where(whereExpression).Take(1).Select(selectExpression));
        }
    }


Cheers.
neil.interactit
Kohai
Kohai
 
Posts: 227
Joined: Wed Dec 03, 2014 2:36 pm
Topics Solved: 6

Re: Db.Single<DB_CustomSetting> exception

Postby SBarnes » Thu Jul 06, 2023 7:09 pm

Hi Neil,

The code you are referring to is actually generated by a set of T4 templates, the actual annotation that is needed is the references annotation that would make orm lite realize its a separate table and read the data from there.

If you are using this inside a ServiceStack service one other option you could use is to actually execute and auto query and specify the fields on the request / query version of DB_CustomSetting (DB_CustomSettingQuery), that way it won't confuse the reference properties as actual fields in the table and only select the columns you want.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Db.Single<DB_CustomSetting> exception  Topic is solved

Postby Mike.Sheen » Fri Jul 07, 2023 1:06 pm

I don't see this error.

I'm using 7.2.1 SR15, but I don't think any SR in this case is relevant.

Attached is a plugin which adds a route to the API of TestDBSingle - which performs the following:

Code: Select all
public DB_CustomSetting Get(TestDBServicesGetRequest request)
{
   return Db.Single<DB_CustomSetting>(x => x.SettingName == "TestSetting");
}


When invoked, it returns the expected result:
TestDBSingle.png


Any chance you can try the attached plugin yourself, to see if you get the error? If you don't then what are you doing different?
Attachments
Plugin Test DB.Single.xml
(25.13 KiB) Downloaded 63 times
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: Db.Single<DB_CustomSetting> exception

Postby neil.interactit » Fri Jul 07, 2023 2:41 pm

Thanks Scott. I have used a similar approach with Scalar/From extension. Pretty sure the idea originated from some VB code of yours doing something similar that I stumbled on ages ago!

Thanks Mike. Not sure what is going on as your test seems to work here ...
image.png


Actually, it would be because Jiwa is obviously more scared of you than me.

Turns out I'm happy with the ScalarSingle approach for the simplified coding. It possibly doesn't perform as well, but it is not in a high volume situation so all good.

Thanks again,
Neil
neil.interactit
Kohai
Kohai
 
Posts: 227
Joined: Wed Dec 03, 2014 2:36 pm
Topics Solved: 6

Re: Db.Single<DB_CustomSetting> exception

Postby Scott.Pearce » Fri Jul 07, 2023 3:13 pm

No worries.
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 742
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 221


Return to REST API

Who is online

Users browsing this forum: No registered users and 1 guest