Posts

Showing posts from July, 2015

Handling Complex Object with angular-formly

Image
angular-formly angular-formly is an AngularJS module which has a directive to help customize and render JavaScript/JSON configured forms. The  formly-form  directive and the  formlyConfig  service are very powerful and bring unmatched maintainability to your application's forms. For more information visit its  GitHub page . Now when you use formly, it actually provide very basic framework for generating forms. But it provide a great extensibility as well. So, here I am going to use that extensibility. Scenario In many practical scenarios, objects are complex, i.e. they have properties which are not of basic type, but are objects itself. For example consider the following JSON object { "address": { "street": "", "city": "", "state": "" }, "name": "" } The name is of simple type, but address is itself an another object. Now issue is with formly we  can easily g

Dapper.Net One-To-Many mapping

While using Dapper.Net, most common and fundamental scenario is to load the result that form one-to-many relationship. After doing some searching and refactoring the idea multiple times, I get a refactored solution. Scenario Consider a simple customer-order scenario. A customer could have multiple orders, while a order will be associated with only one customer. The models are: public class Customer     {         public String CustomerId { get; set; }         public String CustomerName { get; set; }         public IEnumerable<Order> Orders { get; set; }     } public class Order     {         public string OrderId { get; set; }         public string CustomerId { get; set; }     } The SQL query to fetch both Customer and Order details is, SELECT * FROM Customers c JOIN Orders o ON c.CustomerId = o.CustomerId ORDER BY c.CustomerId Solution Now, the only issue is how to associate each order with its customer. For this we will need a  mapper , to do the mapp