Today I Learned #3: Solving Comeonin problems on Windows!

Hello there!

I did some Elixir tutorial back in the day and there was a need for Comeonin lib. It’s used for hashing passwords, so you store them securely. I had enormous problems with mix deps.compile because of it.

Here’s what you do if you stumble with deps error

  1. The long way:
    1. Open cmd
    2. Go to Program Files (x86)\Microsoft Visual Studio 14.0\VC
    3. Type vcvarsall.bat amd64
    4. !important! using THE SAME cmd window go to you project
    5. Compile – you have to redo all the steps everytime 🙁
  2. Easy way:
    1. Use Pbkdf2 algorithm. It needs no C compiler 😀

And I used the second way while developing something mine. Works like a charm. As for me algorithm didn’t really matter (each own has it’s own pros and cons) I went with the least problematic one.

PS: What’s funny for some there’s no need for being in the same console/repeating those steps, but I wasn’t that lucky 🙁

Today I Learned #1

While using EntityFramework in my integration tests (which is a separate topic 😉 ) I discovered quite interesting thing. I guess this may be obvious to some, but I learned Entity “the hard way” jumping into an app with Entity already in place and had to adapt – this was my first app with a database by the way.

So if you add entities to your context I’m used to adding all entities to context, so the code would look like

using (var ctx = new Context())
{
    var first = new FirstEntity { .. };
    var second = new SecondEntity { .. };

    ctx.FirstEntities.Add(first);
    ctx.SecondEntities.Add(second);
    ctx.SaveChanges();
}

But if entities are related, you can safely do this

using (var ctx = new Context())
{
    var first = new FirstEntity { .. };
    var second = new SecondEntity { Relation = first };

    //this will also take care of the first one!
    ctx.SecondEntities.Add(second); 
    ctx.SaveChanges();
}

Or even this!

using (var ctx = new Context())
{
    var second = new SecondEntity { Relation = new FirstEntity{ .. } };

    ctx.SecondEntities.Add(second);
    ctx.SaveChanges();
}

It’s nice and saves some typing! 🙂

Today I Learned #0

This is Today I Learned – some nice things I learned, too short to be valid blog post, but too important/interesting/etc to not be written down

While exposing classes to WCF service, you have to use [DataContract] (for class) and [DataMember] (for properties) attributes. Or do you?

Turns out that around 3.5 you don’t have to do it. If you provide class with no attributes it will work out of the box! Where’s the catch? There are two:

  1. You will lose some of features, like naming, being able to serialize private properties, declaring something as required. While some can be more useful than others in specific scenarios – just ask yourself – should you really send private data? 😉
  2. And this is important! If you dare to use [DataMember] on some properties – only those will be serialized.