Context.Facility .Select( c=> new CityModel {ID = c.CityID, Name = c.CityName} ) //Column Order must be same as following GroupBy columns .OrderBy ( c=> c.Name ) .GroupBy ( c=> new { c.Name, c.ID } ) //Multiple Column GroupBy .Select ( c=> c.FirstOrDefault() ) //To filter out repeating .ToList();
Tuesday, September 1, 2015
How to use LINQ to select an object with order by and group by
Javascript Prototype
Every JS object has a prototype.
All JS objects inherit their properties/methods from their prototype.
The standard way to create an object prototype is to use object constructor function:
If you want to add function/property for all person object, you need to user prototype.
All JS objects inherit their properties/methods from their prototype.
The standard way to create an object prototype is to use object constructor function:
function person(first, last age) { this.firstName = first; this.lastName = last; this.age = age; }; var farther = new person("Frank", "Zhang", 40); farther.Country = "Canada"; //Add methods/property to the exist object father.name = function () { return this.firstName + " " +this.lastName; }You can extend the object with new function and new properties as above. However, the new added function/property are limited only for the class you defined as above.
If you want to add function/property for all person object, you need to user prototype.
person.prototype.name = function () { return this.firstName + " " + this.lastName; };
Last but not least, Never modify the prototypes of Standard Javascript Objects.
Javascript Revealing Module Pattern
The Revealing Module Pattern is based on a pattern referred to as the Module Pattern. It makes reading code easier and allows it to be organized in a more structured manner. The pattern starts with code like the following to define a variable, associate it with a function and then invoke the function immediately as the script loads. The final parenthesis shown in the code cause it to be invoked.
Source: http://weblogs.asp.net/dwahlin/techniques-strategies-and-patterns-for-structuring-javascript-code-revealing-module-pattern
var Calculator = function () { service1 = function() {......} service2 = function() {......} return { myService1: service1, myService2: service2 } };You can define which members are publicly accessible and which members are private. This is done by adding a return statement at the end of the function that exposes the public members.
Source: http://weblogs.asp.net/dwahlin/techniques-strategies-and-patterns-for-structuring-javascript-code-revealing-module-pattern
How to set Knockout Radio Button with a Default Value
If you want to set default value for radio button checked, you need to use an observable attribute with variable values, and each one is a real value for one radio button.
within data-bind = "checked: TransferType"
TransferType: ko.ovservible("room") <== Init value
for radiobutton's onchange() event, within the c# code:
ViewModel.TransferType("floating");
within data-bind = "checked: TransferType"
TransferType: ko.ovservible("room") <== Init value
for radiobutton's onchange() event, within the c# code:
ViewModel.TransferType("floating");
Kendo Invisible Control Tips
If you want to make Kendo control such as dropdown list invisible, you should put them within <div></div> and put the <div> invisible, so that the dropdown list still be accessible through JQuery.
Knockout Binding
Textbox Binding
<input type="text" id ="txtFirstName" data-bind="value: Employee.FirstName"/>
Textbox Binding
<input type="radio" id="rdoMale" data-bind="checked: Employee.Gender" name="gender" value="0" />
<input type="radio" id="rdoMale" data-bind="checked: Employee.Gender" name="gender" value="1" />
Staging or Not Staging
Data extracted, transformed and loaded (ETL) from the source to destination may require temporary staging for various reasons such as addressing failures, reducing load on the source system, data cleansing, auditing purposes etc.
Whether you need to stage the data or not as part of your ETL process is common design decision that you have to make.
The opportunity to avoid a staging database is even greater when using SSIS, which allows you to apply multiple transformations to data as it passes through memory between the source and the destination.
Also, if the source is simple and clean enough that it does not need any data cleansing or transformations before loading to warehouse then it is a simple mapping without the need of a separate transformation process. The required data is extracted, mapped and loaded to warehouse, is the scenario here.
Source: http://biarchanddesignguide.codeplex.com/releases/view/6572
Whether you need to stage the data or not as part of your ETL process is common design decision that you have to make.
Not Staging
In most simple scenario, the ETL process copies data from the source directly to the data warehouse. In this case, if there is a failure, you restart the job, again extracting data from the source system.The opportunity to avoid a staging database is even greater when using SSIS, which allows you to apply multiple transformations to data as it passes through memory between the source and the destination.
Also, if the source is simple and clean enough that it does not need any data cleansing or transformations before loading to warehouse then it is a simple mapping without the need of a separate transformation process. The required data is extracted, mapped and loaded to warehouse, is the scenario here.
Factors for Staging
- There is a time lag between Extraction and Loading process. If the extraction occurs at 7 AM and the loading to the warehouse happens at midnight then the extracted data has to be stored somewhere. A staging database is a reasonable option.
- Restart on failure: If various parts of the ETL process are vulnerable to fail, recovery is easier if a staging database is available as the starting point. For example, Out of 100 tables, the extraction process is failed after extracting 60 files to staging area successfully. When the extraction process is restarted it does not need to extract all but the failed 40 as the data is already available for successful 60 in staging. When the source system resources are constrained, it is particularly important to avoid repeating an extract unnecessarily. The staging database allows the Extraction process to be decoupled from the subsequent processes.
- Memory Constraints. Some transformations particularly those that require sorting, can consume substantial memory resources. In many cases, those transformations can be done more efficiently by making use of a disk-based staging. Depending entirely on memory availability limits the ability of the ETL process to scale. When there are memory intensive transformations, having a disk-based process allows for more growth in the volume of data you can process.
- Auditing Requirements. Depending on the specifics of the extraction and transformation process, a staging area can provide a level of auditing support. For example, if it turns out that a specific customer is missing from the data warehouse, you could examine the staging database to help identify why that customer’s records were lost.
- Multiple Source systems: When the data is to be consolidated from multiple source systems, a staging database allows the consolidating to take place before processing the transformation.
Subscribe to:
Posts (Atom)