For MSDN subscribers VS10 .NET framework 4 Beta 2 is available on this wednesday .
Download it from here
Success is a journey , It’s not a destination
For MSDN subscribers VS10 .NET framework 4 Beta 2 is available on this wednesday .
Download it from here
If the query is like this
adventureworksEntities dbEntities = new adventureworksEntities();var query = from PC in dbEntities.productcategoryjoin PSC in dbEntities.productsubcategoryon PC.ProductCategoryID equals PSC.ProductSubcategoryIDselect new { PC.Name, PC.ModifiedDate, PSC.Name, PSC.ModifiedDate };
The compiler will throw the error,”An anonymous type cannot have multiple properties with the same name” .Because the compiler can’t able to find a proper Name.So we want to modify the query with alias name ,some thing like this.
var query = from PC in dbEntities.productcategoryjoin PSC in dbEntities.productsubcategoryon PC.ProductCategoryID equals PSC.ProductSubcategoryIDselect new { PCName1 = PC.Name, PCModifiedDate1 = PC.ModifiedDate, PSCName1 = PSC.Name, PSCModifiedDate1 = PSC.ModifiedDate };
As we all know that Entity Frame work supports multiple databases.Here i am converting MSSQL database to MYSQL,Without changing the query.That is the power of linq.
First i am doing one sample on MSSQL.
I am using AdventureWorks Database, and using 2 tables ,Production.ProductCategory and Production.ProductSubcategory.
The ER Diagram for Production.ProductCategory and Production.ProductSubcategory is shown below
Steps to Add Entity Frame Work for MSSQL
Step 1 : Right Click on Solution Explorer –> Add –> New Item –> Select ADO.NET Entity Data Model.
Step 2 : Select sever name and AdventureWorks as DataBase and Click ok
Step 3 : Click Next
Step 4 : Select two tables Production.ProductCategory and Production.ProductSubcategory and Click Finish
So your Edmx Looks like
Code for getting the data
Here i cannot use Debug Visualizer.Entity Frame work wont support Debug Visualizer.So i am using one gridview and dispaly the data.AdventureWorksEntities dbEntities = new AdventureWorksEntities();var query = from PC in dbEntities.ProductCategoryjoin PSC in dbEntities.ProductSubcategoryon PC.ProductCategoryID equals PSC.ProductSubcategoryIDselect new { PCName = PC.Name, PCModifiedDate = PC.ModifiedDate, PSCName = PSC.Name, PSCModifiedDate = PSC.ModifiedDate };GridView1.DataSource = query;GridView1.DataBind();
Note : If you are getting the error “An anonymous type cannot have multiple properties with the same name “ Read this
Output shown in Gridview.
The same result i am getting from MYSQL without changing the query.Only i am changing the database from MSSQL to MYSQL.
Converting MSSQL to MYSQL by using Full Convert Enterprise .
Steps to CovertStep 1 : Already created AdventureWorks DataBase in MYSQL.
Step 2 : Enter username and Password
Step 3 : I selected all tables selected to convert MYSQL.
Step 1 : install Connector/ NET 6.0 Windows Binaries,it automatically install mysql.data.dll and mysql.data.entity.dll to GAC.
Step 2 : Right Click on Solution Explorer –> Add –> New Item –> Select ADO.NET Entity Data Model.The result will display as same result.adventureworksEntities dbEntities = new adventureworksEntities();var query = from PC in dbEntities.productcategoryjoin PSC in dbEntities.productsubcategoryon PC.ProductCategoryID equals PSC.ProductSubcategoryIDselect new { PCName = PC.Name, PCModifiedDate = PC.ModifiedDate, PSCName = PSC.Name, PSCModifiedDate = PSC.ModifiedDate };GridView1.DataSource = query;GridView1.DataBind();
By using this query we can alter the schema to SCHEMANAME .
select 'ALTER SCHEMA SCHEMANAME transfer ['+SCHEMA_NAME(schema_id)+'].['+name +']' from sys.tables
OUTPUT
select all the query and execute in query window.All the schema will automatically changes to SCHEMANAME
Note :sys.tables – Returns a row for each table object ,currently only with
sys.objects.type =U
SCHEMA_NAME(schema_id) – Returns the schema name associated with schema_id
schema_id – ID of the schema.Schema_id is a int. If schema is not defined schema name of default will return
E.g : select SCHEMA_NAME() from sys.tables
OUTPUT
For Procedure
select 'ALTER SCHEMA SCHEMANAME transfer ['+SCHEMA_NAME(schema_id)+'].['+name +']' from sys.procedures
For UDF
select 'ALTER SCHEMA SCHEMANAME transfer ['+specific_schema+'].['+specific_name +']'
FROM information_schema.routines
WHERE routine_type='function'
Note : routines - Returns one row for each stored procedure and function that can be accessed by the current user in the current database.
Its a .NET Static analysis tool for Architecture and developers to analyze the code structure,specify design rules , do some massive code review , compare different versions of code etc . This tool is developed by Patrick Smacchia(C# MVP).
Main features of NDepend are as follows as
To read more
This is the sample program i am going to analyze by using NDepend.
using System;using System.IO;using System.Collections.Generic;interface IFirst{int AgeFirst { get; set; }string NameFirst { get; set; }}interface ISecond{int AgeSecond { get; set; }string NameSecond { get; set; }}abstract class abstractClass{int Ageabstract { get; set; }string Nameabstract { get; set; }}class Program{static void Main(string[] args){}}
As we all know that the interface is not derived from System.Object.
and the abstract is derived from System.Object.
The Dependency Matrix in NDepend helps to See things graphically.
There are lot of things like Code Query Language(CQL), Detect Dependency Cycles,Compare Builds etc are there to explore in NDepend tool.That i will cover the the upcoming parts.
If any one interested in this tool, have a look on NDepend and order it Now.
Note : Thanks Patrick Smacchia, for given a free licence of NDepend to write a review.
Microsoft MVPs are awarded every quarter and recognise the contributions of an individual to technical communities over the past year. read more