1. Don Olliver
  2. SnapObjects
  3. Monday, 19 August 2019

Using PB 2019, we have migrated several datastores to a SnapDevelop .NET assembly. Looking through the various tutorials and sample projects, we do not see any examples of accessing datastore column values using object dot notation. All appear to use GetItem and SetItem for this purpose, as shown below.

intProductId = product.GetItem(0, "productid");
dataStore.SetItem(0, "name", OrderReportMonth1.GetItem(0, "subcategoryname"));

--------------

intPersonId = businessEntity.GetItem(0, "businessentityid");
person.SetItem(0, "businessentityid", intPersonId);

--------------

var productPhoto = new DataStore("d_productphoto", _context);
productPhoto.AddRow();
productPhoto.SetItem(0, "LargePhotoFileName", photoname);
productPhoto.SetItem(0, "modifieddate", DateTime.Now);

Can .NET datastore column values be accessed by some flavor of dot notation, such as

product.object.product_id[1]?

Would someone please provide a few examples of object dot notation use?

 

Thanks,

Don Olliver

Accepted Answer
Logan Liu Accepted Answer Pending Moderation
1
Votes
Undo

Hi Don,

Sorry, I missed your concerning about how to set values to .Net DataStore like object dot notation in PowerScript.

You asked a very good question. We can't set data by the LINQ style, because the reference of the inner models haven't been exposed to the developers. Appeon is already researching on how to provide a better strongly-typed data accessing solution for .NET DataStore. 

In current version, you can use SetModel() method to work around it:

            // Gets the third row (a new model object).
            var row = ds.GetModel(2);
            
            // Changes its name (D_Department.Name property).
            row.Name = "New Name";
            
            // Sets values back to the third row of DataStore.
            ds.SetModel(2, row);

Regards,

Logan

Comment
There are no comments made yet.
  1. Wednesday, 21 August 2019
  2. SnapObjects
  3. # Permalink
Don Olliver Accepted Answer Pending Moderation
0
Votes
Undo

Hi Logan,

One more question. Are GetItem and SetItem the best options to use from a performance perspective? Or, should we consider LINQ querying and SetModel()?

Thanks,

Don

Comment
Hi Don,



I can't compare their performance simply, because they are used in 3 different scenarios:

For GetItem() and SetItem() methods, they can access value of a specified column of a row. If you only want to set value for one column of a row, GetItem() and SetItem() have better performance in most time.

For AddModel(), GetModel() and SetModel() methods, they can access a row of data. If you want to insert a new row, or set values for many columns of a row, in most time, these generic methods have better performance.

For AsEnumerable, it takes a data buffer of DataStore as a IEnumerable object. Then you can use LINQ querying to do operations that are more complex to query the data.



Regards,

Logan
  1. Logan Liu
  2. Friday, 23 August 2019
There are no comments made yet.
  1. Wednesday, 21 August 2019
  2. SnapObjects
  3. # 1
Don Olliver Accepted Answer Pending Moderation
0
Votes
Undo

Thanks very much Logan. We will decide which syntax standards to enforce as we convert our PowerScript code.

Don

Comment
There are no comments made yet.
  1. Wednesday, 21 August 2019
  2. SnapObjects
  3. # 2
Don Olliver Accepted Answer Pending Moderation
0
Votes
Undo

Hi Logan,

Thanks very much for providing access examples. Would you use the same methods to set data?

Don

Comment
There are no comments made yet.
  1. Tuesday, 20 August 2019
  2. SnapObjects
  3. # 3
Logan Liu Accepted Answer Pending Moderation
2
Votes
Undo

Hi Don,

You can use LINQ to acess data in .Net DataStore for instead. It can display errors directly during the encoding process and achieve more maintainable code. E.g.:

            var ds = new DataStore("d_department", _dataContext);

            ds.Retrieve(id);

            var data = ds.AsEnumerable();
            
            // Gets deptId at index 2 (the third row)
            int departmentId = data.ElementAt(2).DepartmentId;

            // Gets the first 3 rows
            var departments = data.Take(3);

            // Gets departmentId, departmentName and GroupName columns
            var result = data.Select(o => new Tuple(o.DepartmentId, o.Name, o.GroupName));

Regards,

Logan

Comment
There are no comments made yet.
  1. Tuesday, 20 August 2019
  2. SnapObjects
  3. # 4
Chris Pollach Accepted Answer Pending Moderation
0
Votes
Undo

Hi Don;

  In the current SnapDevelop release, the DOT notation is not supported in C#.

Regards ... Chris

Comment
There are no comments made yet.
  1. Monday, 19 August 2019
  2. SnapObjects
  3. # 5
Olan Knight Accepted Answer Pending Moderation
0
Votes
Undo

Try it out!

While I don't know the answer to your question, if dot notation is possible it SHOULD look a lot like the PB Classic dot notation, so give it a try!

Olan

 

Comment
Hello Olan, I am part of the team that is attempting to use the .NET datastores and we did give it try and it didn't work. We were actually wondering if there was something that needed to be initialized or setup in order to enable this feature or whether this feature is even available for the .NET datastore since we cannot seem to find any examples of it being utilized in this way.
  1. Bernie Rivera
  2. Monday, 19 August 2019
Hi Bernie, Please take a look at Logan's post in this thread about how to achieve same functionality using standard C# approach.
  1. Armeen Mazda
  2. Tuesday, 20 August 2019
There are no comments made yet.
  1. Monday, 19 August 2019
  2. SnapObjects
  3. # 6
  • Page :
  • 1


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