「初始化字串的格式和開始於索引 0 的規格不相符」
「Format of the initialization string does not conform to specification starting at index 0」
相信使用Entity Framework Code-First的開發者一定有人遇過,在本機開發環境做了Add-Migration XXX和Update-Database之後看起來都沒問題,發佈設定檔裡面也勾了啟用Code-First移轉,然後發佈到遠端主機上,開心的期盼.Net會自動更新資料庫,結果總是出現這個錯誤...
2015-12-05
2015-10-02
[筆記]讓新版EF6的Skip、Take語法支援SQL Server 2008
最近在寫一個簡單MVC專案,有用到分頁,在本機測試時,分頁一切正常,但是發佈到遠端Server時,竟然出現底下錯誤:「接近 OFFSET 之處的語法不正確。FETCH 陳述式中的選項 NEXT 使用方式無效」
覺得奇怪,到底花生省魔術?
覺得奇怪,到底花生省魔術?
標籤:
.net,
ef6,
mvc,
sql server
2014-11-24
ASP.NET MVC - 如何讓Form參數內的XML字串綁定到Model
最近在學習MVC,目前有個需求,需要使用者將Form Post到某個Action內,裡面的參數還會有xml文字,整個參數會像底下一樣:
其中A與B是普通字串,而C是XML字串
在Visual Studio 2013裡有個好用的功能,可以將XML或JSON字串轉成Class,只要使用選擇性貼上即可。底下就是寫好的一個使用者參數的Model:
A=123&B=abc&C=<Root><A>123</A><B>abc</B><C>kkk</C><D>iii</D></Root>
其中A與B是普通字串,而C是XML字串
在Visual Studio 2013裡有個好用的功能,可以將XML或JSON字串轉成Class,只要使用選擇性貼上即可。底下就是寫好的一個使用者參數的Model:
public class SendModel
{
[Required(AllowEmptyStrings = false, ErrorMessage = "{0}不可為空")]
[StringLength(3, MinimumLength = 3, ErrorMessage = "{0}長度必須為{2}")]
public string A { get; set; }
[Required(AllowEmptyStrings = false, ErrorMessage = "{0}不可為空")]
[StringLength(3, MinimumLength = 3, ErrorMessage = "{0}長度必須為{2}")]
public string B { get; set; }
[Required(AllowEmptyStrings = false, ErrorMessage="xml不可為空,請檢查格式是否正確")]
public SendXmlModel C { get; set; }
//這個類別就是將XML貼上之後所產生的,格式相同就可序列化成字串或反序列化回該類別的物件
[Serializable]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
[System.Xml.Serialization.XmlRootAttribute("Root", Namespace = "", IsNullable = false)]
public partial class SendXmlModel {
public string A { get; set; }
public string B { get; set; }
public string C { get; set; }
public string D { get; set; }
}
}
訂閱:
文章 (Atom)

