SQLite EntityFramework 6 Tutorial

ErazerBrecht's Blog


UPDATE 13/10/2015/
I made another post about MVVM and EntityFramework. After reading this, you should really check that one out!
It’s really worth it to use MVVM 🙂
Link to another post: Click Here

I’ll explain the basics to get SQLite working with EntityFramework 6. It’s a straight forwarded tutorial / explanation. I will not tell you everything about EF (there are a lot of tuturials on the web). Instead I’ll show you the most basic example to get EF working with SQLite, after all it wasn’t that easy!

View original post 1,783 more words

Mocking Entity Framework DbContext with Moq

Mirko Maggioni

When we have to test methods that involves Entity Framework, a typical choice that we have to face is use integration tests, with an effective database, or unit tests.

If we choice the first option, with a database like SQL LocalDB, we’ll have performance problems because the cost of the database creation and the data inserts in the test startup is very high, and in order to guarantee the initial conditions we’ll have to do it for each test.

What we can do is use a mock framework that help us to mockup the entity framework context; it would be an in-memory db context, like the in-memory db context of .NET Core, that we have seen in this post.

The factory

In pratice, mocking a class means substitute the real implementation of a method with our custom behaviour; what we can do for every method of the class is…

View original post 482 more words

C# Regrets: Top Worst C# Features

Stumbled upon this article written by no other than Eric Lippert listing the top 10 design faults of C# language. Here is the summary,  the source to the full article is at the bottom. 

#10: The empty statement does nothing for me

Reflects on the fact that lone “;” is a legal statement

#9: Too much equality

There are too many ways check for equality: ==, Equals, ReferenceEquals, CompareTo(…).

From personal experience double.NaN == double.NaN is false but double.NaN.Equals(double.NaN) is true

#8: That operator is shifty

Weirdness around << and >> operators

#7: I’m a proud member of lambda lambda lambda

The way C# 2.0 implements anonymous delegates

#6: Bit twiddling entails parentheses

Flags Enums

#5: Type first, ask questions later

C# borrows the “type first” pattern from C and many of its other successor languages – something I got used to and the “correct” way now seems illogical to me

#4: Flag me down

The fact that you can create invalid enum values and have to manually check for this in the code

#3: I rate plus-plus a minus-minus

++i, i++, i +=1 etc. how much confusion and the pain it caused.

#2 I want to destruct finalizers

Agree with the author that finilisers in C# are symptoms of a bug. Seen it way too many times myself.

#1 You can’t put a tiger in the goldfish tank, but you can try

“array covariance” and how this could lead to run-time exceptions.

Source: http://www.informit.com/articles/article.aspx?p=2425867

Structs, C#7 and Performance Improvement 

C# 7 provides a very powerful feature from the performance standpoint. This feature is returning by ref. Essentially this allows for value types to be returned without having to copy them.

The guidelines are normally that you shouldn’t use a struct with too many fields. Various sources quote various size guidelines. Whenever the struct was over the prescribed size it was recommended that you pass it by reference.

With the new syntax for returning types by reference, it’s now more convenient (no more methods returning via out parameter) to use structs. 

In performance critical scenarios where you need to avoid polluting managed heap with too many Gen #0 objects using structs has now become more natural. In the past dealing with structs was somewhat cumbersome if you dealt with a large number of fields and needed to avoid copying of values. 

I have worked on a large application at McLaren – Telemetry Acquisition System that is supplied to all teams. The performance of the application is very critical as it has to process gigabytes of telemetry data. We have used structs extensively to squeeze out every bit of performance from .NET runtime.

I think it’s my second favourite feature after value tuples.

C# 7.0

Rahul's space

C# History

In all previous versions of C# (with the exception of C# 6.0 maybe) new features have revolved around a specific theme:

  • C# 2.0 introduced generics.
  • C# 3.0 enabled LINQ by bringing extension methods, lambda expressions, anonymous types and other related features.
  • C# 4.0 was all about interoperability with dynamic non-strongly typed languages.
  • C# 5.0 simplified asynchronous programming with the async and await keywords.
  • C# 6.0 had its compiler completely rewritten from scratch, and introduced a variety of small features and improvements that were easier to implement now.

C# 7.0 is no exception to this rule. The language designers were focusing on three main themes:

  • Working with Data – Increased usage of web services is changing the way data is being modelled. Instead of designing the data models as a part of the application, their definition is becoming a part of web service contracts. While this is very convenient…

View original post 1,825 more words

Top 10 C# projects errors found in 2016

I’m not the only one who got burnt by ThreadStatic

How Not To Code

To measure the efficiency of our analyzer, and also to promote the methodology of static analysis, we regularly analyze open source projects for bugs and write articles about the results. 2016 was no exception. This year is especially important as it is the year of the “growth” of the C# analyzer. PVS-Studio has obtained a large number of new C# diagnostics, an improved virtual values mechanism (symbolic execution) and much more. Based on the results of our teamwork, I compiled a kind of chart of the most interesting bugs, found in various C# projects in 2016.

Picture 3

View original post 1,367 more words

Want to learn WPF? Get a book

Sorin Dolha's Blog

I’ve said it before. In my opinion, WPF is the single contemporary programming technology (disclaimer: among those that I’ve considered myself) that really requires a book to learn it. Otherwise, trying to dig using just hands on testing – as it’s indeed possible in many other cases – you might think you know enough before you do and you’ll get frustrated every day later because things won’t work the way you’d think they should. This StackOverflow question – that triggered this post – is only an example. I personally have been there too (and after the WPF experience, now I decided that I’ll always learn complex new technologies using books, although it may be unnecessary in some cases, as I’ve seen before WPF.)

But don’t get scared. Mastering WPF by starting learning it from the core instead of from the surface will provide many, many benefits that will overcome any…

View original post 146 more words

Battling Anaemia 

The week before last,  on Thursday I suddenly felt something in the stomach, it wasn’t painful, felt more like a cramp. That happened around 14:30 then around 17:40 I decided to go home, stood up and could feel that my heart was racing. I initially thought nothing of it and decided to go home. However as soon as I tried to cross the road I felt that something was seriously wrong with me and I had to sit down. I then slowly proceeded to the closest tube station but even that proved extremely difficult.

I finally gave in and got a cab that took me to the train station. Thinking about the stomach cramp I had earlier I thought I had a bad sandwich and one day off sick should do it.

Meanwhile I could barely walk and after getting to the second floor of my house my blood pressure would skyrocket to 160/110 and my pulse would be around 130bpm. Everyone around me was commenting on how pale I looked,  suggesting I go to the A&E. Initially I refused,  but later I realised that I’m not getting any better and the A&E wouldn’t be such a bad idea.

So my dad drove me to the local hospital (my mum works there as well) and we went to the A&E. Expecting to wait for ages I was actually admitted relatively quickly, by then I really looked very sick. A nurse took few vials of my blood and sent me back to the waiting room.

Half an hour later they asked for me again but this time I was greated by a guy with the wheel chair! This is where I got really really scared. Then the nurse told me that the lab called them to tell that my haemoglobin level was 49 g/L (this is dangerously low, versus normal 160 g/L) and I require an emergency blood transfusions and would remain in the hospital. I was beyond scared by this point.

They said that normally people collapse when their haemoglobin levels are that low and the fact that I was relatively “alive” meant that my body got used to it. After even the first unit of blood (308ml) I felt almost high and full of energy. The consultant said that I require at least 4 units to get my levels above critical (1.2 litres in total). Each bag takes about 2-3 hours and my transfusions lasted well into the night. By then I was moved to the observation ward.

Next morning I was taken for the ultra-sound, and then for upper endoscopy (which was “fun” as I didn’t feel any sedation) , as they were thinking that I must have a bleed somewhere resulting in slow blood loss. Nothing was found.

Next day at the hospital they took about 20 vials of my blood for various tests. The consultant haematologist couldn’t find anything either apart from my still very low haemoglobin (81 g/L after all transfusions).

In the end I was discharged with a diagnosis of “iron deficiency anaemias”.  Which means that I either don’t absorb enough iron (celiac disease would do that for example)  or have a bleeding somewhere in my lower GI. I was given a bunch of ferrous sulphate pills to help maintain my iron levels.

Upon discharge from the hospital I was still a bit high from the blood transfusions, but that quickly subsided. Then all the “pleasant” symptoms from anaemia appeared – extreme chills (I would wear my hoodie even if it was +24 in a room), shortness of breath, headache, low grade fever, anxiety, inability and unwillingness to do anything, insomnia, night sweats, inability to regulate body temperature. Every day I would measure my blood pressure to gauge how hard my heart was working. If I had been sitting for 2 minutes or more my blood pressure was perfect 117/77, however if I did something slightly physically demanding it would again skyrocket to about 140/100. After 5 days of taking the medication I wasn’t feeling any better. Every day would be like a Groundhog day to me – I would wake up at 6 after only sleeping 4-5 hours and having nightmares. I would then sit quietly on the sofa wearing everything to get worm, even though the room temperature was never below 23C. I would then spend the whole day watching telly and sleeping which in turn would make my insomnia even worse.

However today is day #10 and it’s the second consecutive day that I suddenly started to feel better – temperature is down, I can walk without stopping, my headaches are gone and so are the chills.

I still have several outpatient procedures to go to establish the exact cause of such acute onset of anaemia.

All in all anaemia sucks big time, because of lack of oxygen in your blood it hurts to think, I couldn’t sit in front of my PC at all,  you hate yourself for not being able to do anything, one of the most unbearable symptoms is the constant feeling of cold. It basically sucks all the will to live out of you!

In the hindsight, my symptoms began long before August this year, now I think that I might have had some anaemia for at least 6-7 years. I’m now looking forward to recovery, and if I had it for a while I wonder how I would feel with the normal haemoglobin levels!

Day #11 and I certainly don’t feel any worse. About to drive to the clinic all by myself!

Blog at WordPress.com.

Up ↑