Click here to Skip to main content
15,886,137 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
NewsExtract from the code I'm working on Pin
Super Lloyd10-Dec-12 16:26
Super Lloyd10-Dec-12 16:26 
GeneralRe: Extract from the code I'm working on Pin
Brisingr Aerowing10-Dec-12 17:57
professionalBrisingr Aerowing10-Dec-12 17:57 
GeneralRe: Extract from the code I'm working on Pin
Super Lloyd10-Dec-12 18:13
Super Lloyd10-Dec-12 18:13 
GeneralRe: Extract from the code I'm working on Pin
KP Lee11-Dec-12 12:08
KP Lee11-Dec-12 12:08 
GeneralRe: Extract from the code I'm working on Pin
Super Lloyd11-Dec-12 22:04
Super Lloyd11-Dec-12 22:04 
GeneralRe: Extract from the code I'm working on Pin
Nemanja Trifunovic13-Dec-12 7:29
Nemanja Trifunovic13-Dec-12 7:29 
GeneralRe: Extract from the code I'm working on Pin
Super Lloyd13-Dec-12 13:12
Super Lloyd13-Dec-12 13:12 
GeneralNo foreign keys on the first date. Pin
Brady Kelly9-Dec-12 2:21
Brady Kelly9-Dec-12 2:21 
I wrote this little workaround earlier this year. EF complains about an insert where ParentId is set, but allows me to set it with an update.
C#
// TODO Address this cluster-wtf.
using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted }))
{
    if (newProject.ParentId != null)
    {
        // I don't know why I need this, but EF won't insert with a ParentId, but allows me to set it immediately after.
        int parentId = newProject.ParentId.Value;
        newProject.ParentId = null;
        _projectRepository.Insert(newProject);
        newProject.ParentId = parentId;
        _projectRepository.Update(newProject);
    }
    else
    {
        _projectRepository.Insert(newProject);
    }
    scope.Complete();
}

GeneralRe: No foreign keys on the first date. Pin
KP Lee11-Dec-12 8:17
KP Lee11-Dec-12 8:17 
GeneralRe: No foreign keys on the first date. Pin
Brady Kelly11-Dec-12 8:34
Brady Kelly11-Dec-12 8:34 
GeneralRe: No foreign keys on the first date. Pin
KP Lee11-Dec-12 11:33
KP Lee11-Dec-12 11:33 
GeneralRe: No foreign keys on the first date. Pin
Pete O'Hanlon11-Dec-12 9:10
mvePete O'Hanlon11-Dec-12 9:10 
GeneralRe: No foreign keys on the first date. Pin
Brady Kelly11-Dec-12 16:36
Brady Kelly11-Dec-12 16:36 
GeneralRe: No foreign keys on the first date. Pin
Andrew Rissing13-Dec-12 6:42
Andrew Rissing13-Dec-12 6:42 
GeneralRe: No foreign keys on the first date. Pin
ryan_b200917-Dec-12 6:55
ryan_b200917-Dec-12 6:55 
GeneralRe: No foreign keys on the first date. Pin
Brady Kelly17-Dec-12 7:04
Brady Kelly17-Dec-12 7:04 
GeneralHow do you like your nulls Pin
Robert Hoffmann8-Dec-12 1:57
Robert Hoffmann8-Dec-12 1:57 
GeneralRe: How do you like your nulls Pin
Brisingr Aerowing8-Dec-12 7:25
professionalBrisingr Aerowing8-Dec-12 7:25 
GeneralRe: How do you like your nulls Pin
lewax008-Dec-12 15:32
lewax008-Dec-12 15:32 
GeneralRe: How do you like your nulls Pin
Brisingr Aerowing8-Dec-12 16:23
professionalBrisingr Aerowing8-Dec-12 16:23 
GeneralRe: How do you like your nulls Pin
lewax008-Dec-12 16:33
lewax008-Dec-12 16:33 
AnswerRe: How do you like your nulls Pin
Robert Hoffmann8-Dec-12 23:55
Robert Hoffmann8-Dec-12 23:55 
GeneralRe: How do you like your nulls Pin
lewax009-Dec-12 0:35
lewax009-Dec-12 0:35 
GeneralRe: How do you like your nulls Pin
Robert Hoffmann9-Dec-12 9:39
Robert Hoffmann9-Dec-12 9:39 
GeneralRe: How do you like your nulls Pin
patbob10-Dec-12 5:32
patbob10-Dec-12 5:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.