Monday, March 21, 2011

How to find out common element(s) in two generic list by LINQ, LINQ Set Operations

int[] twos = { 2, 4, 6, 8, 10 };
int[] threes = { 3, 6, 9, 12, 15 };

// 6
var intersection = twos.Intersect(threes);

// 2, 4, 8, 10
var except = twos.Except(threes);

// 2, 4, 7, 8, 10, 3, 9, 12, 15
var union = twos.Union(threes);

Understand SQL Injection by code

If put the following string in the SSN text box
' ; DROP DATABASE pubs  --
Using the input, the application executes the following stored procedure, which internally executes a similar SQL statement.
SqlDataAdapter myCommand = new SqlDataAdapter(
                                "LoginStoredProcedure '" +
                                 SSN.Text + "'", myConnection);

The code INJECT into the user's malicious input and generates the following query.
SELECT au_lname, au_fname FROM authors WHERE au_id = ''; DROP DATABASE pubs --'
 
Reference: 
How To: Protect From SQL Injection in ASP.NET

Sunday, March 20, 2011

How to select value into variable in MS SQL

Declare @RowCount int
set @RowCount = (select COUNT(*) from INFORMATION_SCHEMA.TABLES)
select @RowCount

How to upgrade to Entity Framework 4.1

http://johnpapa.net/silverlight/upgrading-to-entity-framework-4-1-rc/

Entity Framework 4.1 is coming with Code First feature

EF 4.1 includes the new “EF Code First” option that I’ve blogged about several times in the past.  EF Code First provides a really elegant and clean way to work with data, and enables you to do so without requiring a designer or XML mapping file.  Below are links to some tutorials I’ve written in the past about it:

http://weblogs.asp.net/scottgu/archive/2011/03/19/rc-of-entity-framework-4-1-which-includes-ef-code-first.aspx