2017年5月10日 星期三

LINQ - Sample Queries

https://code.msdn.microsoft.com/LINQ-Sample-Queries-13a42a54

This sample contains about 101 examples from each of these areas:

LINQ To Objects
LINQ To SQL
LINQ to DataSet
LINQ to Xml

DbContext和DbSet類別

不管透過哪種方式整合Entity Framework,關鍵還是在DbContext和DbSet這兩個類別

DbContext:
透過DbContext物件與資料進行連線溝通

DbSet:
利用DbSet物件封裝要處理的資料

Entity Framework 實務精要 第117頁

2017年5月7日 星期日

IPv4和IPv6資料庫定義的長度

http://stackoverflow.com/questions/3455320/size-for-storing-ipv4-ipv6-addresses-as-a-string

15 characters for IPv4 (xxx.xxx.xxx.xxx format, 12+3 separators)
39 characters (32 + 7 separators) for IPv6

2017年5月6日 星期六

HtmlHelper和UrlHelper差異

HtmlHelper用於產生超連結(a標籤)
UrlHelper只有輸出URL網址

HtmlHelper的ActionLink方法:
@Html.ActionLink("相簿", "Carousel", "Album")
 =>產生相簿超連結

UrlHelper的Action方法:
@Url.Action("Carousel", "Album")
 =>產生/Album/Carousel(只有文字,沒有超連結)

@Url.Action("Carousel", "Album", new { message = "3" })
 =>產生/Album/Carousel?message=3 (message 型別是string)

@Url.Action("Carousel", "Album", new { id = "3" })
 =>產生/Album/Carousel/3 (id型別是int)

Razor大括號程式區塊輸出文字


@:要輸出的文字

Razor的註解

@*我是註解*@

2017年5月5日 星期五

ViewData和ViewBag

ViewData:
可利用ViewData設定顯示在前端的資訊
在頁面中可以透過ViewData取得後端來的資料
ViewData只能對一個Action有作用
生命週期只存在於單一頁面,若網頁導向後,ViewData的資料會被清除

宣告
ViewData["Message"] = "Hello World";

使用
@ViewData["Message"]
=>會在頁面印出Hello World

ViewBag:
ViewBag和ViewData有一樣的功能,差別在ViewBag可動態產生屬性,利用dynamic這個型別包裝,使用ViewBag時不需再進行類別的轉換

宣告
ViewBag.Message = "Hello World";

使用
@ViewBag.Message
=>會在頁面印出Hello World

ViewData和ViewBag用途:
ViewData和ViewBag是用在Controller及View之間傳遞資料
如果要在Controller及Controller之間傳遞資料須使用TempData

ASP.NET MVC4.0實務專題範例教學 第6-15、6-17頁

2017年5月3日 星期三

SQL Server顯示執行的sql指令在哪一筆失敗

Get line number in file following TSQL error message
http://stackoverflow.com/questions/27785390/get-line-number-in-file-following-tsql-error-message


Invoke-SqlcmdEx
https://github.com/mnaoumov/Invoke-SqlcmdEx

Invoke-SqlcmdEx(Use LINENO approach)
https://github.com/mnaoumov/Invoke-SqlcmdEx/blob/LINENO/Invoke-SqlcmdEx.ps1

TempData和ViewData的差異

TempData預設會將資料存在Session,生命週期是一整個Request,即使網頁轉向還是可以取得資料

備註:TempData和ViewData皆是實作IDictionary介面

2017年5月2日 星期二

Microsoft.ReportViewer.WinForms

NuGet安裝
PM> Install-Package microsoft.ReportViewer.WinForms

Using the WinForms ReportViewer Control

https://docs.microsoft.com/en-us/sql/reporting-services/application-integration/using-the-winforms-reportviewer-control

RDLC、RDL和SSRS的差異

ReportViewer! RDLC!
http://blog.darkthread.net/post-2009-01-31-reportviewer-rdlc.aspx
滿不錯的介紹文章
英文原文: http://www.gotreportviewer.com

MICROSOFT® REPORT VIEWER 2012 RUNTIME

https://www.microsoft.com/zh-TW/download/details.aspx?id=35747

需要先安裝Microsoft SQL Server System CLR Types package
https://www.microsoft.com/zh-tw/download/details.aspx?id=35580
下載SQLSysClrTypes.msi


Generate class from database table



以Northwind的Customers為例,會產生以下程式碼
public class Customers
{
    public string CustomerID { get; set; }

    public string CompanyName { get; set; }

    public string ContactName { get; set; }

    public string ContactTitle { get; set; }

    public string Address { get; set; }

    public string City { get; set; }

    public string Region { get; set; }

    public string PostalCode { get; set; }

    public string Country { get; set; }

    public string Phone { get; set; }

    public string Fax { get; set; }

}

(T4)tt檔和cs檔之間傳遞變數資料

How do I pass a string parameter to a t4 template
http://stackoverflow.com/questions/15946802/how-do-i-pass-a-string-parameter-to-a-t4-template

(TSQL)組出DAOImpl.cs所需程式碼


(TSQL)組合出TRUNCATE TABLE等指令