Skip to content

Instantly share code, notes, and snippets.

@bpraveen4u
bpraveen4u / IQueryableExtensions.cs
Created June 29, 2021 23:57 — forked from leniency/IQueryableExtensions.cs
Modifications to allow CamelCase.NestedProperties
/// <summary>
/// Provides projection mapping from an IQueryable sourceto a target type.
///
/// This allows from strongly-typed mapping and querying only necessary fields from the database.
/// It takes the place of Domain -> ViewModel mapping as it allows the ViewModel to stay as
/// IQueryable. AutoMapper works on in-memory objects and will pull all full records to perform
/// a collection mapping. Use AutoMapper for Input -> Domain scenarios, but not DAL.
///
/// Reference: http://devtrends.co.uk/blog/stop-using-automapper-in-your-data-access-code
/// </summary>
@bpraveen4u
bpraveen4u / dynamic_type.cs
Created November 8, 2012 05:18
Dynamic Type (C# Reference) output through linqpad
void Main()
{
dynamic dyn = 1;
object obj = 1;
dyn = dyn + 3; // No Compilation Error
//obj = obj + 3; //Compilation error (Operator '+' cannot be applied to operands of type 'object' and 'int')
System.Console.WriteLine(dyn.GetType());//typeof (Int32)
System.Console.WriteLine(obj.GetType());//typeof (Int32)
@bpraveen4u
bpraveen4u / custom_decimal_format.cs
Created November 5, 2012 06:50
Custom decimal format for specific regional settings
void Main()
{
//this sample Works great in Linqpad
Console.WriteLine("Custom Decimal format in en-US region settings ");
var culture = new System.Globalization.CultureInfo("en-US");
Console.WriteLine(string.Format(culture,"\t{0:#,0.00} : {1:#,0.00}", 1234256.55583, 123344256.555));
Console.WriteLine(string.Format(culture,"\t{0:#,0.00}", 7200));
Console.WriteLine(string.Format(culture,"\t{0:#,0.00}", 0.005));
Console.WriteLine(string.Format(culture,"\t{0:#,0.00}", -0.006));
@bpraveen4u
bpraveen4u / merge_datatable.cs
Created November 5, 2012 06:26
Merge Two DataTables and remove duplicate rows
void Main()
{
DataTable table1 = new DataTable("Items");
// Add two columns to the table:
DataColumn column = new DataColumn("id", typeof(System.Int32));
table1.Columns.Add(column);
column = new DataColumn("item", typeof(System.String));
table1.Columns.Add(column);