2014年3月30日 星期日

Linq Extension Mapping

1. Union

IQueryable<T> x;
IQueryable<T> y;

var rslt = x.Union(y);


2. Union all

IQueryable<T> x;
IQueryable<T> y;

var rslt = x.Concat(y);





2014年3月21日 星期五

SqlException from Entity Framework

在Foreach中加入 Entity framework 的SaveChanges 出現這個錯誤:

"New transaction is not allowed because there are other threads running in the session"

可以參考這篇微軟的回答

解決方式請參考  ~

(以下內容為轉貼 stackoverflow)

// 1: Save after iteration (recommended approach in most cases)
using (var context = new MyContext())
{
    foreach (var person in context.People)
    {
        // Change to person
    }
    context.SaveChanges();
}

// 2: Declare an explicit transaction
using (var transaction = new TransactionScope())
{
    using (var context = new MyContext())
    {
        foreach (var person in context.People)
        {
            // Change to person
            context.SaveChanges();
        }
    }
    transaction.Complete();
}


2014年3月11日 星期二

[C#] 讀取資源檔


var rm = new System.Resources.ResourceManager(
"UseResourceBinary.Properties.Resources", System.Reflection.Assembly.GetExecutingAssembly());

rm.GetString("XXX");

2014年3月3日 星期一

威力彩中了八百元 :Q

剛才在建立威力彩預測模型的訓練資料時,

發現上次的號碼中了六獎~~  第一次中這麼前面的 ...

結果一看只有八百元 =..=

希望明天手氣會更好!! osu