29 Haziran 2012 Cuma

get ID of an entity before SaveChanges()

Unfortunately, when using automatically generated ID s in database, it is not possible to get the ID before doing SaveChanges().

http://stackoverflow.com/questions/6029711/id-of-newly-added-entity-before-savechanges/6029864#6029864

how to write content of dictionary to file

In order to write the content of a dictionary to a file:


        public static void writeDictToFile(Dictionary dict, string filename) {
            File.WriteAllLines(filename + ".txt",
            dict.Select(x => "[" + x.Key + " " + x.Value + "]").ToArray());
        }

http://stackoverflow.com/questions/3067282/how-to-write-the-content-of-a-dictionary-to-a-text-file

27 Haziran 2012 Çarşamba

html vertical line

Unfortunately, there is no explicit element in html in order to draw a vertical line .. However, there are 3 ways to achieve this:
<td width="5%"style="border-left: 1px solid black; padding: 5px;">   </td>
2) With 1-pixel image
3) With css (div) 


Another option is to draw very thick and short horizontal line: http://forum.yola.com/yola/topics/vertical_lines_using_html

25 Haziran 2012 Pazartesi

error : The underlying connection was closed: The connection was closed unexpectedly.

If the error
{"The underlying connection was closed: The connection was closed unexpectedly."}
blows up for some of the web service methods, while others work correctly, the reason may be the return objects refer to each other in a recursive manner. 
In my condition, i got the error while returning Sentence.
Paragraph() {
     List<Sentence> Sentence;
}
Sentence() {
  List<Paragraph> SomeText;
}
When the type of SomeText is changed from Paragraph  to Sentence, everything works fine!

error: LINQ to Entities does not recognize the method ...Last

The complete error message is as follows :


{"LINQ to Entities does not recognize the method 'Core.Sentence Last[Sentence (System.Collections.Generic.IEnumerable`1[Core.Sentence])' method, and this method cannot be translated into a store expression."}

and the causing line is:


retList = (dal.Paragraph.Include("Sentence").Where(p => p.Sentence.Last().Topic.ID == topic.ID)).ToList();

This is because Last and LastOrDefault are just not supported by the LINQ to SQL query translator.
http://forums.asp.net/t/1480557.aspx/1

The solution is ordering Sentence in descending order and use FirstOrDefault instead of Last:

 retList = (dal.Paragraph.Include("Sentence").Where(p => p.Sentence.OrderByDescending(s => s.ID).FirstOrDefault().Topic.ID == topic.ID)).ToList();