April 17, 2019
On entity framework on deletion one-to-many it is possible to cascade delete entities. However, if foreignKey is nullable, this relation should be set to null, and EF does it automatically with one small catch: only if entity is in memory.
If it is doesnt loaded, then it will throw ugly error The DELETE statement conflicted with the REFERENCE constraint
.
To avoid that, load entity implicitly by any possible method like Include()
or using Queryable.Load
like that:
Context.Entry(parentEntry).Collection(p => p.SubItems).Load();
here We load all SubItems, that have a foreign key to ParentEntry and, when we delete it later, all those keys sets to null automatically.
More about this here
February 25, 2019
When I have bought new iPhone with preinstalled ios 12 and new Shortcuts app, it was naturally for me to start automate everything, that I'm doing on a phone. But, there were not so many:
I have created morning shortcut (turn off sleep mode, show weather & todo list), and evening routine (even simpler: set do not disturb mode, open alarm app).
All automation solutions, that I see in macstories or hear in numerous podcasts did not clicked for me. But the more I'm playing with this, the more I realize, that I can do more with a phone and implement new ways of interaction. Creating new shortcuts or scripts in Scriptable or actions in Drafts is not very easy, or even possible sometimes. The hardest part is to actually find new things to automate and find what can be actually usefully, and not just produce whistles, that were made for fun and neglected on next day. I'll try to make posts time to time to describe what I'm doing and what I got from these scripts.
As quick example, I have added several actions to Drafts. Each of them consist from one step: call callback url to Things to create new todo.
things:///add?titles=[[draft]]
things:add?title=[[title]]¬es=[[body]]
things:add?title=[[title]]&checklist-items=[[body]]
things:add?title=[[title]]¬es=[[body]]&when=saturday&list-id=ED7BB6BD-7F6C-466B-84AD-B9C5E580D51F
Since I have added these actions, I hardly ever add new tasks directly in Things app. By and large, Drafts app become my input method in phone and I hope to write more about it later.
February 24, 2019
I havent done anything to this blog in last year. After fixes in mar 2018 I have added ping endpoint in august (it took me almost 10 minutes, including deployment!), then I have removed file watcher in christmas, because someone from linode contacted me and kindly asked to stop using 100% of cpu all the time.
But I have big plans for this blog in this year and already started by changing way how to push new posts. Previously I have used scp to upload them to server and filewatcher catched them. After I have disabled it, I had to restart app each time, when I post something (that is twice a year). aLthough I have finally remember scp syntax, I want to have something simplier and easy to do using just phone.
Now I store all posts in github (thanks MS, they added private repositories), and add webhook to pull each time something pushed to "publish" branch. This seems not a very complex stuff, but I have added libgit2sharp to project, repository to use it, cleaned code (and posts structure - now it loads from all directories recursively, images in separate folder etc) - and all of it using 20 minutes before sleep time breaks.
I could have played zelda in that time... 😭
btw, this post I have created just to test git sync, do not read it, it is boring
February 7, 2019
On my main job we have a project, that contain all kinds of technologies. Mostly it us angularJs or razor pages, but we got also knockout, that works in pair with signalr. This cause many problems and one of the technical debt currently is to replace signalr hubs to ajax calls. But problem is we cant do this at once, we have to support both versions at the time to turn it off, if something goes south. Now coffeescript is packed with checkings, what to call, but problem is that in response from server signalr hub return parameters in camelCase, and ajax return in CamelCase. I got a strong feeling, that if I will add another useSignalR checking, this code will be cursed forewher, so I wrote small function:
replaceAttributesToLowerCase: (object) ->
for propertyName in Object.keys(object)
lowerCaseProperty = propertyName.toLowerCase()
object[lowerCaseProperty] = object[propertyName]
return object
Rare beauty of javascript flexibility, heh 😎 Also now all parameters are lowercase in whole class, which is severely breaking naming conventions. And it double object size in memory. But in my opinion, all parts of projects, that contain knockout, coffeescript or signalr should be buried.
December 3, 2018
One of the very first projects in my career was php (plain php, no frameworks, no js) cms system for medical facilities. By that time, I didn't know how web works (I mean, I knew even less than now) and my coding skills were very rough. I have spent 3 years in support and happily left the company in early 2013. And today I have found, that this project is still alive, used and they haven't changed admin password 🤪
Somewhere in this site there are my own implementation of mvc and orm.. even before I knew about these pattern or read GoF book.
This has the shittiest code, that I have ever wrote for production and I think, by far the oldest that is still in use.
100% JS-free