Showing posts with label Devevlopment. Show all posts
Showing posts with label Devevlopment. Show all posts

Friday, 17 January 2014

SQL Server Data Tools Projects Error with the file _Data.sqlinclude


I am having problem to build the project.  The error is:

  • SQL71006: Only one statement is allowed per batch. A batch separator, such as 'GO', might be required between statements.

Solution:

  • Set the Build Action of the file to "None".  It was set to "Build".

More info:

  • Make sure the file (Data\_Data.sqlinclude) is NOT Read Only.
  • Have a Pre-Build event to generate the file with Data\_Data.tt


set doTemplateTransform=
if "$(BuildingInsideVisualStudio)"=="True" set doTemplateTransform=true

if "%doTemplateTransform%"=="true" "$(MSBuildProgramFiles32)\Common Files\microsoft shared\TextTemplating\12.0\TextTransform.exe" "$(ProjectDir)Data\_Data.tt" -a "!!targetDir!$(ProjectDir)Data"

Thursday, 28 November 2013

Using Table as layout in HTML 5

The HTML5 specification still recommends that you don't use tables for layout, but if you do, you should differentiate those tables from tables that are used for tabular data.

Features to Define Your Table as Layout or Non-Layout

Feature of Table Is a Layout Table?
<table role="presentation"> It probably is a layout table
<table border="0"> It probably is a layout table
<table cellpadding="0"> It probably is a layout table
<table cellspacing="0"> It probably is a layout table
Use of the CAPTION, THEAD, or TH elements It probably is not a layout table
Use of the headers and scope attributes on the TH element It probably is not a layout table
<table border=""> It probably is not a layout table
<table border="1"> It probably is not a layout table
Visible borders set with CSS It probably is not a layout table

Thursday, 21 March 2013

Web Application targets IE 9 and above...

Add this to the master page or the shard layout file, and IE will not go into the compatibility mode (IE 8)
  • <meta http-equiv="X-UA-Compatible" content="IE=9" />

Friday, 8 March 2013

Idempotent

Calling the function a million times has the same effect as one request.

Example:
WebAPI Uniform Interface:
  • GET, PUT and DELETE

Friday, 21 December 2012

Ubiquitous Language

A core principle of domain-driven design is to use a language based on the model.

Wednesday, 19 December 2012

Create a DDD Solution


Starting a New Solution

  • Create a Blank Solution
  • Add a Core Class Library Project
  • Add an Infrastructure Class Library Project
  • Add your UI project (Console, WinForms, WPF, ASP.NET MVC)
  • Add references to Core from Infrastructure and UI 
  • Add a reference to Infrastructure from UI

  • Add a Controller, View
  • Add an Interface <IMyInterface> (new folder "Interfaces" in Core) with a method
  • Implement the Interface in Infrastructure (in a class <MyInterface>) with the method
  • In the controller:
  • Add the private field of the <IMyInterface>
  • Add the constructor with <IMyInterface> as parameter
  • Add the constrcutor without parameter to add the parameter
  • In the control, call the method and show the result to the view



Onion Architecture Principles

All code depends on layers closer to center (Domain Model)
Inner layers define interfaces; outer layers implement these interfaces
Layered behavior around the Domain Model
Infrastructure and UI concerns pushed to edge
  • Depend on Application Core, not vice versa



Dependency Inversion Principle (DIP)

High-level modules should not depend on low-level modules.  Both should depend on abstractions.
Abstractions should not depend on details.  Details should depend on abstractions.

Domain-Centric Design / Domain Driven Design

The problem-space of your application is its domain.  If you are going to write a banking software system, you need to have a good understanding of what banking is all about, you must understand the domain of banking.

A domain is something of this world and we need to create an abstraction (a blueprint) of the domain to transform the domain into software constructs.  The abstraction is a model, our internal representation of the target domain.

The model is the common ground, the place where the software meets the domain.

The objects you design to model the domain are domain objects (model objects / model).
  • Encapsulate application business logic and rules
  • Maintain any state required to do so
  • Do not depend on external infrastructure concers


Tuesday, 4 September 2012

Shallow Copy and Deep Copy


Shallow copy versus deep copy is only meaningful with "reference types" and not with "value types".

Shallow Copy
http://0.tqn.com/d/visualbasic/1/0/4/a/dsgnshlwdeepcopy-1.gif
Deep Copy
http://0.tqn.com/d/visualbasic/1/0/6/a/dsgnshlwdeepcopy-Dup.gif


Wednesday, 20 June 2012

Responsive Web Design

Responsive design is a style of web design that responds to the user as they arrive at the web page. The design will display the content most effectively with different devices.

Web pages must be flexible and adapt, they must look different depending upon what is displaying them.

Don't crate separate websites for each device, it is only a quick and dirty approach.

Responsive design treats mobile and desktop the same. But the pages that are created may look vastly different, while containing the same content.

CSS media queries were introduced as part of CSS3 and they improved on the idea of media types by looking at the actual physical specifications being sent from the browser to the computer.


 For example, to send a specific style sheet only to iPhones, you would write:
<link rel="stylesheet" type="text/css" media="screen and (max-device-width: 480px)" href="480-styles.css"> 

This can handle any device that has a width less than 480px.

Small Screen Need the Important Things First

Monday, 2 April 2012

An anonymous type (vb.net)

Objects can be initialized as an anonymous type without even creating or naming a class.

Dim myObject = New With { .id = 1, .type="dog", .name="hello" }

The compile will create and initialize a type for you.

With the "Key" keyword, it will allow you to select exactly which variables in an anonymous type should be used in either the calculation of a hashcode (using GetHashCode) or an equality comparison.


Dim myObject = New With {Key .id = 1, Key .type="dog", Key .name="hello" }

Dim myObject2 = New With {Key .id = 1, Key .type="dog", Key .name="hello" }


Console.WriteLine(myObject.GetHashCode)
Console.WriteLine(myObject .Equals(myObject2 ))

Thursday, 15 March 2012

Multiple Main Methods in C#

Specify the Startup object in the Project Properties, Application tab.


Make sure the Main() method takes no parameters, or a single array of string ("string", not "String").  It should also returns nothing, or an int.  Otherwise, the main method(s) won't be shown in the dropdown list.



        static void Main(string[] args)
        {
 
        }

        static void Main()
        {
 
        }

Monday, 5 March 2012

Removing VSS files from a solution

Remove the Read-only Attribute of the files

Remove the mssccprj.scc, vssver.scc <solution>.vspsscc and <solution>.suo files in the solution folder
Remove the mssccprj.scc, vssver.scc and <project>.csproj.vspscc files in the project folder

Remove the GlobalSection(SourceCodeControl) in the solution (<solution>.sln) file

Remove the following lines from the vb project file (<project>.vbproj/<project>.csproj):
  • SccProjectName = "SAK"
  • SccLocalPath = "SAK"
  • SccAuxPath = "SAK"
  • SccProvider = "SAK"
or
  • <SccProjectName>SAK</SccProjectName>
  • <SccLocalPath>SAK</SccLocalPath>
  • <SccAuxPath>SAK</SccAuxPath>
  • <SccProvider>SAK</SccProvider>

Remove vssver.scc in all folders




Thursday, 1 March 2012

Entity Framework and Database


By default, when you use Entity Framework Code First to automatically create a database, as you did earlier in this tutorial, Code First adds a table to the database to help track whether the schema of the database is in sync with the model classes it was generated from. If they aren't in sync, the Entity Framework throws an error. This makes it easier to track down issues at development time that you might otherwise only find (by obscure errors) at run time. The sync-checking feature is what causes the error message to be displayed that you just saw.

There are two approaches to resolving the error:
  1. Have the Entity Framework automatically drop and re-create the database based on the new model class schema. This approach is very convenient when doing active development on a test database, because it allows you to quickly evolve the model and database schema together. The downside, though, is that you lose existing data in the database — so you don't want to use this approach on a production database!
  2. Explicitly modify the schema of the existing database so that it matches the model classes. The advantage of this approach is that you keep your data. You can make this change either manually or by creating a database change script. 

Wednesday, 29 February 2012

LINQ to SQL


LINQ to SQL makes database programming a direct part of the VB.NET/C#  language. Before it was added to the language toolkit with Framework 3.5/VB.NET 2008, databases were a world apart from your application programming code and you had to get your data through an interface. Coding for SQL Server this way doesn't take advantage of some of the best features of VB.NET/C# development such as the use of  Intellisense. (Using older methods, the tables and fields in the database are unknown to the VB.NET code so Visual Studio can't tell you whether your names are right or wrong. And the compiler can't tell you whether your SQL commands are correct because they're passed directly to SQL Server. Your code has to be able to interpret whatever comes back from SQL Server.)

There are basically two problems to be solved when accessing a SQL Server database from your application:
  1. Data in a database doesn't have the same "types" as data in .NET. This is often called the database "impedance mismatch".  The process of converting types from a database into types in an application is called object relational mapping (ORM).  Today, LINQ to SQL provides a new tool in Visual Studio, the Object Relational Designer, and just takes care of the rest of the problem.
  2. SQL statements have to be passed to the database engine for execution and results (or errors) returned to the application. The SqlClient namespace in ADO.NET provides the ExecuteReader, ExecuteNonQuery, and ExecuteScalar methods to run queries. Part of the problem is that it's not always clear which one to use. LINQ to SQL gives you VB.NET/C# statements that you can compile in your application and eliminates the need to use these methods. The new LINQ to SQL syntax looks a lot like traditional SQL too.
Create SQL to SQL:
  1. Add database connection
  2. Add DataContext (LINQ to SQL Classes) (".dbml")

The bottom line is that LINQ to SQL is a lightweight technology that can make your SQL Server coding faster and easier. It's a good choice for most projects, but if you need the best performance or if your application has complex requirements, you might want to go the traditional route or consider the ADO.NET Entity Framework.

Relational Data Model            LINQ to SQL Object Model 
----------------------------     -------------------------------
Table                            Entity class
Column                           Class member 
Foreign-key relationship         Association 
Stored Procedure or Function     Method


Entity Framework

The Entity Framework provides a completely independent "conceptual model" of the data. When you use the Entity Framework, you code queries against this conceptual model and not against the actual data store. Entity Framework has its own dialect of SQL used to retrieve data called Entity SQL. It's not SQL Server's TSQL query language. In fact, the data store does not have to be a database.

The conceptual model contains what Microsoft calls "entities". The Entity Framework adds a layer of software to your application that maps the data from a data store to these entities. Of course, the data store still has to provide the data so the Entity Framework "conceptual model" has to be created and configured before it will work in your code.

LINQ to SQL gives you the ability to access a SQL Server data store using VB.NET/C# language elements.
LINQ to Entities gives you the abilty to access the Entity Framework model, which could potentially include data from any data store, using VB.NET/C# language elements.

Entity Framework can provide the many-to-many relationship in the data model automatically.

Install "Microsoft Visual Studio 2010 ADO.NET Entity Framework Tools"
Create the Entity Framework conceptual model
Right click on the project, select Add, New Item..., Data, ADO.NET Entity Data Model


Microsoft gives you two ways to access the data in the Entity Framework model:
  • LINQ to Entities
  • Entity SQL (A variant of the venerable SQL language just for the Entity Framework)
Since Entity Framework implements both IQueryable (used more in Entity Framework) and IEnumerable (used in LINQ), you actually get the advantages of both worlds.

more info...

LINQ

"Language INtegrated Query"

LINQ can be used to create and filter data into arrays, enumerable classes, XML, relational databases, and other data stores. You can even use LINQ query expressions as the basis for statements like building event handlers. This is one of the reasons LINQ can be confusing.


    From ...
    Where ...
    Select ...


LINQ adds the abililty to use the powerful query syntax.  LINQ is "language level" querying.

more info...

Technologies access Data in Microsoft world


ADO.NET
  • works directly through an API (program calls to an interface) that calls the internal functions of the database or other datastore
  • for maximum performance
LINQ to SQL
LINQ to DataSet
LINQ to Entities
Entity Framework

all use ADO.Net as their foundation