Browse Category

C#

Accessing Entity Framework’s items with little help of metadata

Sometimes, when we work with database, we have to do some changes is some specific tables. It can be situation when we need correct some corrupted data in our system or compare some specific columns in tables between two databases. Instead of manual work with T-SQL scripts and spending effort to keep them up to date, we can write some program which will make our life easier on the one hand, and will save our time when it will come to maintenance. If we can use an ORM like Entity Framework then we can generate the model from the database, but here nice part ends. Now we will have few solutions available:

  • inspect our model with the help of “reflection” to discover the columns and properties which require our interference
  • modify T4 template, with which EF creates his objects, to inject some base classes or interfaces and to try to access the objects that way. Unfortunately not always we have opportunity to work with nicely structured database and not always making a change in T4 template is an easy task.
  • we can try to access metadata of Entity Framework and more easily access interesting objects for us to perform our modifications.

How we can access the metadata? Let’s see below
Keep Reading

Thread & CurrentCulture

Recently I had quite interesting situation I was not fully aware of. The problem was, that user got the message from my application in one language, although he started application with another one.
What had happened was – the operation was executed in another thread, which had different culture settings (specific to local machine) than culture settings of my application – as a result other resources where read 🙂
Keep Reading

One NuGet please!

Gdybym wiedzial, ze tak bedzie, to bym tak nie zrobil“… czasem mozna powtarzac to jak mantre. Ktos kiedys, podejmuje jakas decyzje, ktora w danym momencie wydaje sie byc dobra (lub jest niedokonca przemyslana :)), decyzje ktora rozwiazuje pewien problem i dziala… dopoki nie pojawi sie inny, nowy 😉 wtedy podejmujemy nowa decyzje, ktora rozwiazuje stary problem, ten nowy i inny..potencjalny (jesli poswiecilismy chwile czasu na zastanowienie sie nad takim). I wszystko dziala… rzecz jasna… do momentu az nie pojawi sie kolejny problem X :). Dzis o jednej z takich decyzji podjetych w odpowiedzi na problem X…
Keep Reading