5 Temmuz 2012 Perşembe

enum support in entity framework

Enumeration support comes with Entity Framework 5, so for prior versions we need a workaround..
I think the workaround in http://dotnetdevdude.com/Blog/2012/01/09/EntityFrameworkCodeFirstEnum.aspx is suitable.  To apply the workaround:
1.   Create two members for the field you want to use as enum type. In the below example,   SentencePart   is an enumaration which specifies parts of a sentence. SentencePartInt  holds an integer value whereas SentencePartEnum  is the member which is going to be used and processed in the code.
       
        public Nullable SentencePartInt{ get; set; }
        public Nullable< SentencePart> SentencePartEnum
        {
            get { return ( SentencePart) SentencePartInt ; }
            set {  SentencePartInt = (int)value; }
        }
       

2.   Tell the database context not  to persist the enum member.
       modelBuilder.Entity().Ignore(x => x. SentencePartEnum );
3.    Use the enum member in the code, not the integer.


4 Temmuz 2012 Çarşamba

pdf to word converter

When there is a time limit for composing a tutorial for something, a good pdf to word converter tool is a life saver. 14-day trial downloaded from http://www.pdftoword.com/ worked for me..
http://www.pdfonline.com/pdf-to-word-converter/ took a while to convert the pdf online and only converted the document partially because of its size..

2 Temmuz 2012 Pazartesi

clean code

While looking for coding best practices, i discovered this book: http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882 . It is very easy to read with funny drawings..
The guidelines in  http://csharpguidelines.codeplex.com/ are worth sharing as well..

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