1. Daniel Richard
  2. .NET DataStore
  3. Thursday, 9 September 2021 13:53 PM UTC

Hi 

I'm still leaning and trying things with Snapdevelop.

I'm tying the generic .Net Datastore and l'm wondering if their is a way of adding DwParameterAttribute dynamically (Where statements).

I know this can be done with the Snapobject via  SqlModelMapper.GetQueryBuilder class and using the Builder.WhereRaw and  Builder.AndWhereRaw methods . 

I can't seems to find anywhere in the documentation that this is doable in the .Net Datastore. 

Is their a way of using the GetQueryBuilder method for querying the DB then copying the data into the DataStore that is efficient.

The reason that I'm trying to stick with the Datastore is that I been using Powerbuilder for a long time and I know the Datawindow/ Datastore.

Would I be better of just using the snapobjects class and not use the Datastore way.

 

Thanks in advance, Daniel

 

 

Daniel Richard Accepted Answer Pending Moderation
  1. Thursday, 9 September 2021 14:03 PM UTC
  2. .NET DataStore
  3. # 1

I'm think I just got my answer  the  ToDataSore() method seems to work.

Here's my latest code  and that seems to work

Daniel

 

var dataStore = new DataStore<Parts_List>(_dataContext);
            
          
            var Builder = _dataContext.SqlModelMapper.GetQueryBuilder<Parts_List>();
            Builder.RemoveWhere();
            Builder.WhereRaw("(description like  :description ) ", SqlBuilder.Parameter<string>("description"));
            Builder.AndWhereRaw("(pk_zones =  :pk_zones or :pk_zones is null) ", SqlBuilder.Parameter<int>("pk_zones"));
            
           var _parts = (Builder.Load("diode%",1)).ToList();
           var ds = _parts.ToDataStore();   
           return ds;

Comment
There are no comments made yet.
Francisco Martinez @Appeon Accepted Answer Pending Moderation
  1. Thursday, 9 September 2021 14:37 PM UTC
  2. .NET DataStore
  3. # 2

Hi Daniel,

There are some extension methods that convert an enumerable to a .NET DataStore, so you could chain them to your QueryBuilder's ToList() method like this:

var dataStore = dataContext.SqlModelMapper.GetQueryBuilder<Model>()
    .WhereRaw(....)
    .ToList()
    .ToDataStore(dataContext);

Please let me know if this helps you

Regards,
Francisco

Comment
There are no comments made yet.
Daniel Richard Accepted Answer Pending Moderation
  1. Thursday, 9 September 2021 16:17 PM UTC
  2. .NET DataStore
  3. # 3

Yes that did the trick.

However had to include the Load() method in the chain link for it to work.

 

  var ds2 = _dataContext.SqlModelMapper.GetQueryBuilder<Parts_List>()
            .WhereRaw("(description like  :description ) ", SqlBuilder.Parameter<string>("description"))
            .AndWhereRaw("(pk_zones =  :pk_zones or :pk_zones is null) ", SqlBuilder.Parameter<int?>("pk_zones"))
            .AndWhereRaw("(Parttype =  :parttype) ", SqlBuilder.Parameter<string>("parttype"))
            .AndWhereRaw("(inactive  =  :inactive) ", SqlBuilder.Parameter<int?>("inactive"))
            .Load(description + "%", pk_zones, parttype, 0, 0)
            .ToList()
            .ToDataStore(_dataContext);
         

 

Thanks Daniel

Comment
  1. Armeen Mazda @Appeon
  2. Thursday, 9 September 2021 19:37 PM UTC
Thanks for sharing the solution!
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.