﻿<?xml version="1.0" encoding="utf-8"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Intersoft Community - Crosslight - How to Use Crosslight Enterprise Framework to Update Calculated Fields</title><link>http://www.intersoftsolutions.com/Community/Crosslight/How-to-Use-Crosslight-Enterprise-Framework-to-Update-Calculated-Fields/</link><description /><generator>http://www.intersoftsolutions.com</generator><language>en</language><copyright>Copyright 2002 - 2015 Intersoft Solutions Corp. All rights reserved.</copyright><ttl>60</ttl><item><title>How to Use Crosslight Enterprise Framework to Update Calculated Fields</title><link>http://www.intersoftsolutions.com/Community/Crosslight/How-to-Use-Crosslight-Enterprise-Framework-to-Update-Calculated-Fields/</link><pubDate>Fri, 07 Aug 2015 16:24:43 GMT</pubDate><dc:creator>jtungol@silentpartnersoft.com</dc:creator><description>Hi Leo,&lt;br&gt;&lt;br&gt;It does seem to work on &lt;span style="font-weight: bold;"&gt;iPad&lt;/span&gt;, &lt;span style="font-weight: bold;"&gt;iPhone&lt;/span&gt;, &lt;span style="font-weight: bold;"&gt;Android Phone&lt;/span&gt; but NOT ON &lt;span style="font-weight: bold;"&gt;Android tablet&lt;/span&gt; with Nested Master/Detail view. When passing the data through NavigationParameter from DataListViewModelBase, the data being passed is being overwritten with the SelectedItem value once it reaches the Navigated event on the ListViewModelBase. This creates an issue because the parameter.Data contains something else rather than the actual data being passed.&lt;br&gt;</description></item><item><title>How to Use Crosslight Enterprise Framework to Update Calculated Fields</title><link>http://www.intersoftsolutions.com/Community/Crosslight/How-to-Use-Crosslight-Enterprise-Framework-to-Update-Calculated-Fields/</link><pubDate>Thu, 30 Jul 2015 02:44:18 GMT</pubDate><dc:creator>leo.c</dc:creator><description>&lt;p&gt;Hi Jimmy,&lt;/p&gt;&lt;p&gt;Insert, Update, and Delete operation on SumListViewModel will be reflected on the Editor A too. To ensure the data, it is recommended that all data operation to Sum Model was done through SumRepository.&lt;/p&gt;&lt;p&gt;Best Regards,&lt;br&gt;Leo&lt;/p&gt;</description></item><item><title>How to Use Crosslight Enterprise Framework to Update Calculated Fields</title><link>http://www.intersoftsolutions.com/Community/Crosslight/How-to-Use-Crosslight-Enterprise-Framework-to-Update-Calculated-Fields/</link><pubDate>Wed, 29 Jul 2015 15:13:14 GMT</pubDate><dc:creator>jtungol@silentpartnersoft.com</dc:creator><description>Awesome! Thanks for the update. We'll see how it works. Just to confirm, any Insert, Delete, Update using ListViewModelBase&amp;lt;Sum&amp;gt; on SumListViewModel will be reflected on Save... right?&lt;br&gt;&lt;br&gt;Thanks!&lt;br&gt;</description></item><item><title>How to Use Crosslight Enterprise Framework to Update Calculated Fields</title><link>http://www.intersoftsolutions.com/Community/Crosslight/How-to-Use-Crosslight-Enterprise-Framework-to-Update-Calculated-Fields/</link><pubDate>Wed, 29 Jul 2015 03:59:31 GMT</pubDate><dc:creator>leo.c</dc:creator><description>&lt;p&gt;Hi Jimmy,&lt;/p&gt;&lt;p&gt;Based on your description, it seem you want to do the following scenario:&lt;br&gt;1. On Editor A Pass RelatedList to a List View&lt;br&gt;2. On ListView, you could go to Editor B to edit item on the list.&lt;br&gt;3. Changes done in Editor B to one of the related item should be reflected on Editor A.&lt;br&gt;&lt;br&gt;I have modified my sample to fit the above scenario. You should be able to get the sample from&amp;nbsp;&lt;a href="https://onedrive.live.com/redir?resid=2EC190ADCD98CB43!119&amp;amp;authkey=!ACW5xaSjpPQywDQ&amp;amp;ithint=file%2crar" target="_blank"&gt;here&lt;/a&gt;. Please note that the sample used crosslight 4. For your information, The data on Editor A and Editor B is the same instance, it just that the changes on Data not reflected on Editor A. So in the sample, I manually trigger property changes on Editor A to update Editor A view. I will discuss it with crosslight development team whether this is the right way to do it. Will give you an update later.&lt;br&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;Best Regards,&lt;br&gt;Leo&lt;/p&gt;</description></item><item><title>How to Use Crosslight Enterprise Framework to Update Calculated Fields</title><link>http://www.intersoftsolutions.com/Community/Crosslight/How-to-Use-Crosslight-Enterprise-Framework-to-Update-Calculated-Fields/</link><pubDate>Tue, 14 Jul 2015 01:34:29 GMT</pubDate><dc:creator>jtungol@silentpartnersoft.com</dc:creator><description>The sample code you provided works because the data being modified on SumEditorViewModel is the same instance with that of the Item.Sum entity
 being passed by the ResultEditorViewModel. But, how do you pass data 
from a DataEditorViewModelBase to another DataEditorViewModelBase with a
 DataListViewModelBase in between, on the same manner that a view model 
sends data to a DataEditorViewModelBase? Say an Editor opens a new list 
and sends an instance of this.Item.SomeRelatedList property (is this 
even possible? sending list data from an editor?). Then, each item from 
SomeRelatedList intance are modified through each editor... and that any
 change to each item should be reflected to the main editor view. 
Picture this... &amp;gt; EDITOR A &amp;gt; LIST &amp;gt; EDITOR B. The calculated 
results for changes on EDITOR B should be reflected on EDITOR A as well.</description></item><item><title>How to Use Crosslight Enterprise Framework to Update Calculated Fields</title><link>http://www.intersoftsolutions.com/Community/Crosslight/How-to-Use-Crosslight-Enterprise-Framework-to-Update-Calculated-Fields/</link><pubDate>Tue, 14 Jul 2015 01:34:09 GMT</pubDate><dc:creator>jtungol@silentpartnersoft.com</dc:creator><description>&lt;p&gt;The sample code you provided works because the data being modified on SumEditorViewModel is the same instance with that of the Item.Sum entity being passed by the ResultEditorViewModel. But, how do you pass data from a DataEditorViewModelBase to another DataEditorViewModelBase with a DataListViewModelBase in between, on the same manner that a view model sends data to a DataEditorViewModelBase? Say an Editor opens a new list and sends an instance of this.Item.SomeRelatedList property (is this even possible? sending list data from an editor?). Then, each item from SomeRelatedList intance are modified through each editor... and that any change to each item should be reflected to the main editor view. Picture this... &amp;gt; EDITOR A &amp;gt; LIST &amp;gt; EDITOR B. The calculated results for changes on EDITOR B should be reflected on EDITOR A as well.&lt;/p&gt;</description></item><item><title>How to Use Crosslight Enterprise Framework to Update Calculated Fields</title><link>http://www.intersoftsolutions.com/Community/Crosslight/How-to-Use-Crosslight-Enterprise-Framework-to-Update-Calculated-Fields/</link><pubDate>Wed, 29 Apr 2015 15:20:28 GMT</pubDate><dc:creator>jtungol@silentpartnersoft.com</dc:creator><description>&lt;p&gt;Awesome! Yes, we've though about the first option you mentioned... but that's not going to work on our design, because the fields can be overridden on the client side. Looks like the second option is the way to go. And yes, we also need changes to related entities as you anticipated. We'll give it a try and see how it's going to work.&lt;br&gt;&lt;/p&gt;
&lt;p&gt;Many thanks!&lt;/p&gt;</description></item><item><title>How to Use Crosslight Enterprise Framework to Update Calculated Fields</title><link>http://www.intersoftsolutions.com/Community/Crosslight/How-to-Use-Crosslight-Enterprise-Framework-to-Update-Calculated-Fields/</link><pubDate>Wed, 29 Apr 2015 06:32:50 GMT</pubDate><dc:creator>leo.c</dc:creator><description>&lt;div&gt;Hi Jimmy,&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;The changes done by database trigger won't be reflected because it was done in database side, so the provider won't aware of the changes. To support this kind of scenario, I propose to you 2 kind of options:&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;1. On Collection entity in dbmx, please set StoreGeneratedPattern for all property that will be changed by database trigger, in this case "Gross" and "CommissionAmount", to "Computed". This will make the property have a value that is generated on both insert and update. The only drawn back for this solution is that your application (WebAPI) will never modify the properties' value.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;2. Refresh/reload your entity (Collection) after save was done. This way, server will surely return the most recent data including the changes form database trigger to client side. The following is an example code in server side to implement this :&lt;/div&gt;&lt;pre&gt;db.AfterSaveChangesDelegate = (context, affectedRows) =&amp;gt;{	var dbEntityEntry = context.ChangeTracker.Entries();	List&amp;lt;DbEntityEntry&amp;gt; collectionEntries = dbEntityEntry.Where(o =&amp;gt; o.Entity.GetType() == typeof(Collection)).ToList();
	foreach (DbEntityEntry collectionEntry in collectionEntries)
	{
		collectionEntry.Reload();
	}
};&lt;/pre&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;In case you need to include related entities to WebAPI response, example database trigger modify a property/column on related entity, you could load the related entity as the following example:&lt;/div&gt;&lt;pre&gt;db.AfterSaveChangesDelegate = (context, affectedRows) =&amp;gt;
{
	var dbEntityEntry = context.ChangeTracker.Entries();
	List&amp;lt;DbEntityEntry&amp;gt; collectionEntries = dbEntityEntry.Where(o =&amp;gt; o.Entity.GetType() == typeof(Collection)).ToList();
	bool relatedAttached = dbEntityEntry.Count(o =&amp;gt; o.Entity.GetType() == typeof(ReleatedEntity)) &amp;gt;= 1;
	foreach (DbEntityEntry collectionEntry in collectionEntries)
	{
		Collection collection = collectionEntry.Entity as Collection;
		if(relatedAttached)
			context.Entry(collection.ReleatedEntity).Reload();
		else
			context.Entry(collection).Reference(c =&amp;gt; c.ReleatedEntity).Load();
	}
 };&lt;/pre&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;I have modified my sample to adopt the second option. Please find the sample&amp;nbsp;&lt;a href="https://onedrive.live.com/redir?resid=2ec190adcd98cb43!117&amp;amp;authkey=!AL-BN5SEZyAK2ss&amp;amp;ithint=file%2crar" target="_blank"&gt;here&lt;/a&gt;. Feel free to share your&amp;nbsp;thought on this.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;Best Regards,&lt;/div&gt;&lt;div&gt;Leo&lt;/div&gt;</description></item><item><title>How to Use Crosslight Enterprise Framework to Update Calculated Fields</title><link>http://www.intersoftsolutions.com/Community/Crosslight/How-to-Use-Crosslight-Enterprise-Framework-to-Update-Calculated-Fields/</link><pubDate>Mon, 27 Apr 2015 21:20:05 GMT</pubDate><dc:creator>jtungol@silentpartnersoft.com</dc:creator><description>&lt;p&gt;Hi Leo,&lt;/p&gt;&lt;p&gt;Thank you for the sample. Do you have a flowchart or a document that illustrates the flow of events or delegates used by the EntityContextProvider? We need to understand how and where to put processes within these events as necessary. The sample you have given us illustrates calculations done on WebApi layer, not on the database itself. It does make sense to process calculations that way if calculations are handled on WebApi controller. However, we need to fetch calculated values after the changes have been saved to the database, not before. The reason being... there are calculations being processed ON AFTER UPDATE triggers that rely on incoming data from client side.&lt;/p&gt;

&lt;p&gt;Okay, let's try to make things simpler. Let's forget about related entities for the time being. Take a look at the table below, with a trigger. This sample indicates that Gross and CommissionAmount are calculated via trigger. In this design, the mentioned fields can be overriden in case the actual cash is not the same with the calculated value. Be that as it may, whatever values generated for these fields should also be fetched by the EntityContextProvider on its return to the client.&lt;br&gt;&lt;/p&gt;

&lt;pre&gt;USE [IntersoftSample]
GO

CREATE TABLE [dbo].[Collection](
    [CollectionId] [bigint] IDENTITY(1,1) NOT NULL PRIMARY KEY,
    [Amount] [money] NOT NULL,
    [Refund] [money] NULL,
    [Gross] [money] NULL,
    [CommissionRate] [smallint] NOT NULL,
    [CommissionAmount] [money] NULL
)
GO

CREATE TRIGGER [dbo].[PostCommission]
   ON [dbo].[Collection]
   AFTER UPDATE
AS 
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    -- Insert statements for trigger here
    IF (NOT UPDATE(Gross) AND
        NOT UPDATE(CommissionAmount))
    BEGIN
        UPDATE
            [dbo].[Collection]
        SET
            Gross = INSERTED.Amount - ISNULL(INSERTED.Refund, 0),
            CommissionAmount = (INSERTED.CommissionRate / 100.00) * (INSERTED.Amount - ISNULL(INSERTED.Refund, 0))
        FROM
            [dbo].[Collection] CO INNER JOIN
            INSERTED ON CO.CollectionId = INSERTED.CollectionId
    END
END
GO&lt;/pre&gt;

&lt;p&gt;Based on the current behavior of EntityContextProvider, is it capable of fetching the calculated values for Gross and CommissionAmount in this scenario if an update is made from client side for Amount, Refund, and/or CommissionRate? Please advise.&lt;br&gt;&lt;/p&gt;

&lt;p&gt;Thanks!&lt;/p&gt;</description></item><item><title>How to Use Crosslight Enterprise Framework to Update Calculated Fields</title><link>http://www.intersoftsolutions.com/Community/Crosslight/How-to-Use-Crosslight-Enterprise-Framework-to-Update-Calculated-Fields/</link><pubDate>Mon, 27 Apr 2015 10:14:28 GMT</pubDate><dc:creator>leo.c</dc:creator><description>&lt;p&gt;Hi Jimmy,&lt;/p&gt;&lt;p&gt;Sorry for the wait. I have create a simple sample that demonstrate this behaviour. Please find the sample &lt;a href="https://onedrive.live.com/redir?resid=2ec190adcd98cb43!115&amp;amp;authkey=!AAjD0QY8qfIV2d0&amp;amp;ithint=file%2crar" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Regarding invoke ExecuteSave on navigation result Callback, I have report this issue under CROS-805. I will keep you informed with the progress of CROS-805.&lt;/p&gt;&lt;p&gt;Best Regards,&lt;br&gt;Leo&lt;br&gt;&lt;/p&gt;</description></item><item><title>How to Use Crosslight Enterprise Framework to Update Calculated Fields</title><link>http://www.intersoftsolutions.com/Community/Crosslight/How-to-Use-Crosslight-Enterprise-Framework-to-Update-Calculated-Fields/</link><pubDate>Wed, 08 Apr 2015 21:23:22 GMT</pubDate><dc:creator>jtungol@silentpartnersoft.com</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;&lt;p&gt;We've probably asked this before, but didn't quite get the answer we're looking for. But, what we need to know is how to update a field on the CLIENT side without raising property changed; thus making the record state as clean. Say for example we have table called &lt;span style="font-weight: bold;"&gt;Table1&lt;/span&gt; that has columns (&lt;span style="font-weight: bold;"&gt;num1&lt;/span&gt;, &lt;span style="font-weight: bold;"&gt;num2&lt;/span&gt;, and &lt;span style="font-weight: bold;"&gt;total&lt;/span&gt;). And all of which are presented to the user using the Form Builder, which accepts inputs in fields num1 and num2 while the &lt;span style="font-weight: bold;"&gt;total &lt;/span&gt;field is a readonly value that is being calculated from the server side. That being said, once the num1 and num2 fields have been populated and sent to the server, the total field on the CLIENT side should be updated with whatever value has been generated from the server side. This way, both values of the TOTAL field on CLIENT and SERVER side are synchronized.&lt;/p&gt;&lt;p&gt;How can we properly implement this with the current version of Enterprise Framework? Does the framework automatically fetch updated data from the server on ExecuteSave? If not, how do we execute an existing command to fetch the updated data from the server and refresh the data within the form?&lt;/p&gt;&lt;p&gt;Please advise. Thanks!&lt;br&gt;&lt;/p&gt;</description></item></channel></rss>