h1.post-title { color:orange; font-family:verdana,Arial; font-weight:bold; padding-bottom:5px; text-shadow:#64665b 0px 1px 1px; font-size:32px; } -->

Pages

Type of Inheritance in Entity Framework

Type of Inheritance in Entity Framework

1) Table-Per-Hierarchy(TPH):

The TPH inheritance states that all entities, in a hierarchy of entities, are mapped to a single table in storage schema. It means, there is only one table in database and different Entity types in Entity model
public class Employee
{
 public int EmployeeID { get; set; }
 public string EmployeeName { get; set; }
}
public class EmployeeDetails : Employee
{
 public string EmployeeAddress { get; set; }
 public string EmployeeMobile { get; set; }
}
public class EmployeeLogin : Employee
{
 public string UserName { get; set; }
 public string Password { get; set; }
}
Entity Framework Code First Mapping for TPH
modelBuilder.Entity<Employee>()
 .Map<EmployeeDetails>(m => m.Requires("Type").HasValue("EmployeeDetails"))
 .Map<EmployeeLogin>(m => m.Requires("Type").HasValue("EmployeeLogin"));

2) Table-per-Type (TPT)
        The TPT inheritance states that each entity in the hierarchy of entities is mapped to a separate table in storage schema. It means, there is separate table in database to maintain data for each Entity Type.
public class Employee
{
 public int EmployeeID { get; set; }
 public string EmployeeName { get; set; }
}
public class EmployeeDetails : Employee
{
 public string EmployeeAddress { get; set; }
 public string EmployeeMobile { get; set; }
}
public class EmployeeLogin : Employee
{
 public string UserName { get; set; }
 public string Password { get; set; }
}
Entity Framework Code First Mapping for TPT
modelBuilder.Entity<Employee>().ToTable("Employee");
modelBuilder.Entity<EmployeeLogin>().ToTable("EmployeeLogin");
modelBuilder.Entity<EmployeeDetails>().ToTable("EmployeeDetails");
Table-per-Concrete-Type (TPC)
          The TPC inheritance states that each derived entity (not base entity) in the hierarchy of entities is mapped to a separate table in storage schema.
          It means, there is separate table in database to maintain data for each derived entity type.
          This inheritance occurs when we have two tables with overlapping fields in the database like as a table and its history table that has all historical data which is transferred from the main table to it.
public abstract class Employee
{
 public int EmployeeID { get; set; }
 public string EmployeeName { get; set; }
}
public class EmployeeDetails : Employee
{
 public string EmployeeAddress { get; set; }
 public string EmployeeMobile { get; set; }
}
public class EmployeeLogin : Employee
{
 public string UserName { get; set; }
 public string Password { get; set; }
}
Entity Framework Code First Mapping for TPC
modelBuilder.Entity<EmployeeDetails>().Map(m =>
{
 m.MapInheritedProperties();
 m.ToTable("EmployeeDetails");
});
modelBuilder.Entity<EmployeeLogin>().Map(m =>
{
 m.MapInheritedProperties();
 m.ToTable("EmployeeLogin");
});

XAML

Introduction to XAML
XAML stands for Extensible Application Markup Language.
Its a simple language based on XML to create and initialize .NET objects with hierarchical relations.
All classes in WPF have parameterless constructors and make excessive usage of properties.
Advantages of XAML
All you can do in XAML can also be done in code.
XAML is just another way to create and initialize objects.
You can use WPF without using XAML.
It's up to you if you want to declare it in XAML or write it in code.

Declare your UI in XAML has some advantages:
XAML code is short and clear to read
Separation of designer code and logic
Graphical design tools like Expression Blend require XAML as source.
The separation of XAML and UI logic allows it to clearly separate the roles of designer and developer.

Properties as Elements
Properties are normally written inline as known from XML <Button Content="OK" />.
we can use the property element syntax. This allows us to extract the property as an own child element.
Syntax:
<Button>
  <Button.Content>
     <Image Source="Images/OK.png" Width="50" Height="50" />
  </Button.Content>
</Button>

Implicit Type conversion
A very powerful construct of WPF are implicit type converters.
They do their work silently in the background. When you declare a BorderBrush, the word "Blue" is only a string.
The implicit BrushConverter makes a System.Windows.Media.Brushes.Blue out of it.
The same regards to the border thickness that is beeing converted implicit into a Thickness object.
WPF includes a lot of type converters for built-in classes, but you can also write type converters for your own classses.
Syntax:
<Border BorderBrush="Blue" BorderThickness="0,10">
</Border>

Markup Extensions
Markup extensions are dynamic placeholders for attribute values in XAML.
They resolve the value of a property at runtime.
Markup extensions are surrouded by curly braces
(Example: Background="{StaticResource NormalBackgroundBrush}").
WPF has some built-in markup extensions, but you can write your own, by deriving from MarkupExtension.
These are the built-in markup extensions:
Binding
To bind the values of two properties together.
StaticResource
One time lookup of a resource entry
DynamicResource
Auto updating lookup of a resource entry
TemplateBinding
To bind a property of a control template to a dependency property of the control
x:Static
Resolve the value of a static property.
x:Null
Return null
Syntax
<TextBox x:Name="textBox"/>
<Label Content="{Binding Text, ElementName=textBox}"/>

Namespaces
At the beginning of every XAML file you need to include two namespaces.
The first is http://schemas.microsoft.com/winfx/2006/xaml/presentation. It is mapped to all wpf controls in System.Windows.Controls.
The second is http://schemas.microsoft.com/winfx/2006/xaml it is mapped to System.Windows.Markup that defines the XAML keywords.
The mapping between an XML namespace and a CLR namespace is done by the XmlnsDefinition attribute at assembly level. You can also directly include a CLR namespace in XAML by using the clr-namespace: prefix.
Syntax:
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
</Window>

Disable UAC

                As most have found out if you disable the UAC (User Account Controls) the desk top gadgets don't work. I found the registy edit that lets you disable UAC and keep the desktop gadgets. I did reboot to see if it works and it does!

using Registry Editor

1. Open Registry Editor (regedit.exe)
2. Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Sidebar\Settings
3. Create a new DWORD Value called AllowElevatedProcess
4. Set the value of the new DWORD to 1
5. Close the registry editor. Your gadgets should work now. No reboot or anything necessary.

using Command Line

C:\Windows\System32\cmd.exe /k %windir%\System32\reg.exe ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 0 /f


Code Sign Vs SSL Certificate

Basically, a code-signing cert gives you a private key that can be verified against a public key certified by a known authority. You make a digital signature with that key, and the other end can verify you had a cert from a trusted source when you signed it.

An SSL cert is just a signed "document" that can be verified as coming from a trusted source. You can't encrypt or sign with it because it doesn't have any key material that's yours alone; it's just a signed document saying "I certify that I trust who this guy says he is."

n SSL Certificate is used for authentication of your website/application server.
A Code Signing Certificate is used for integrity/authentication of the exe,dll,... you deliver.

Get Connectionstring from app.config

Get Connectionstring from app.config



<connectionStrings>
    <add name="myConnectionString" connectionString="server=localhost;database=myDb;uid=myUser;password=myPass;" />
  </connectionStrings>

Output

 string connStr = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
            MessageBox.Show(connStr);

Get User settings

Get User settings

Input
<userSettings>
        <TestSetting.Properties.Settings>
            <setting name="CompanyName" serializeAs="String">
                <value>Gantec</value>
            </setting>
        </TestSetting.Properties.Settings>
    </userSettings>

Output
MessageBox.Show(Properties.Settings.Default.CompanyName);

Get AppSettings.config File in C#.net

Get AppSettings.config File


Input


<configuration>
  <appSettings>
    <add key="ShowQuery" value="true"/>
  </appSettings>
</configuration>

Output

ConfigurationManager.AppSettings["ShowQuery"];

Prevent Multiple Instance Running

Prevent Multiple Instance Running

In Program.cs file add the below code.
 static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Process[] process = Process.GetProcessesByName(Application.ProductName); //Prevent multiple instance
if (process.Length > 1)
{
MessageBox.Show("{Application Name}  is already running. This instance will now close.", "{Application Name}",
MessageBoxButtons.OK, MessageBoxIcon.Information);
Application.Exit();
}
else
{
Application.Run(new <Initial Form>());
}
}

Visual Studio 2013 New Features

Visual Studio 2013 New Features

  • Roaming Settings
  • CodeMap – Visual Debugging
  • Peek Definition – Alt+F12
  • Code Lens
  • New Blue Theme
  • UI Icons
  • Feedback & Notifications
  • Enhanced Scrollbar
  • Navigate To (Ctrl+,)
  • Auto Brace Complete
  • Move Line Up/ Down (Alt Arrow-Up/ Arrow-Down)
  • Minor Tweaks

Using Overloading method via Interface in C#.Net

Here the Example for Using Overloading method via Interface in C#.Net

Interface Name: IFamily
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FactoryPattern
{
    interface IFamily
    {
        string DisplayName(string str);
    }
}
Interface Name: IFamilyMember
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FactoryPattern
{
    interface IFamilyMembers
    {
        string DisplayFamilyMembers(string str);
        string DisplayName();

    }
}
ClassName: ClsFamily
Interface Name(s):IFamily ,IFamilyMembers
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FactoryPattern
{
    class ClsFamily :IFamily ,IFamilyMembers
    {
        public string DisplayName(string str)
        {
            return str;
        }
        public string DisplayFamilyMembers(string str)
        {
            return str;
        }
        public string DisplayName()
        {
            return "Good";
        }
    }
}
Class Declaration and Call Methods
  ClsFamily obj = new ClsFamily();
   MessageBox.Show(obj.DisplayName("Naraayanan"));
   MessageBox.Show(obj.DisplayFamilyMembers("Naraayanan"));            MessageBox.Show(obj.DisplayName());