Archive | Technology

22 March 2018 ~ 0 Comments

ASP.NET Core 2 Not Seeding? Try this!

I had recently created a fairly decently sized application, consisting of about a dozen models, a handful of controllers and a heaping serving of views.  Now, the standard school of thought for seeding data into the database is to create a class in your models and call it in your program startup.  You then have your seeding object check each table for data and insert data as needed.

This has worked for me for the most part, until this project.

I wish I had taken screenshots of the errors, but unfortunately I did not. I was having a lot of problems with concurrency, a second operating started on this project, or that the object has been disposed.

I toyed with it for hours trying to get everything to work properly, sometimes one of the sets of data would seed and other times others would seed, and it even seemed to vary depending on the speed of the system I was using.  I tried breaking everything out into individual methods, awaitng tasks in async methods, and countless re-ordering to try and get the most complete version of the data I could, I even ended up presenting the project with slightly incomplete data as the non-fatal error occurred again during the presentation.  Thankfully nobody knew ahead what I had intended the end result to be, so it went completely unnoticed.  But I knew.

I believe the culprit to be The Async methods required by Identity to create user accounts, roles, and assign roles.  I found the positioning of these seemed to have the most impact on which sets of data would generate errors.

The solution came to me randomly, but is quite simple and could potentially be a better way to seed data than the way I was taught in college and discussed earlier.

It’s a very simple solution, just place your seed data and checks in the constructors for your repositories.   After I split up the data into the repositories the database was seeding flawlessly.  It solved concurrency issues since it was only inserting when the repo object was instantiated rather than all the data nearly simultaneously.

In practice it functions exactly the same way that seeding the data would through a specific seeding class, in that you would have it check the table for entries and then generate them.  Of course, if you don’t need initial data for any of the tables then you won’t have to worry about seeding those tables.

Lastly, as a simple reminder, your seed data will is semi-permanent in an application so it may be worthwhile to make it something meaningful as opposed to just hollow test strings.

Let me know in the comments if this information is useful to you, or if you have anything to add or any other methods for seeding data that myself and other readers may not be familiar with.  Thanks!

 

Continue Reading

07 June 2015 ~ 0 Comments

Everyone’s staring at their phone… and it’s a good thing.

I5B5uBA[1]

It’s not uncommon to see people staring at their cell phone.

It’s also not uncommon to hear people complain about it.

Thanks to the internet we have access to more information, and people, than we have ever had at any other point in existence.  Every day more and more information is uploaded, there will be more information available to me tomorrow than there was today.

I’d like to argue that this is a good thing.

Trivial things like standing in line, waiting for your number to be called at the DMV, waiting for an order to arrive… these things that were usually filled with complete inactivity, sitting, standing, staring, have been forever altered.

Remember when people used to say that there weren’t enough hours in a day? Now you can research subsarahan climates while waiting in line at Starbucks, or send a photo of your son to your Mother, and catch up with her while making dinner.

What you’re seeing is people who now have more choices, they’re choosing to do something enriching with time that was otherwise lost.

The only time you have complainers, is when someone is on their phone while you are trying to have a discussion with them.   They are telling you something, they are telling you that something is more important than your conversation – and they’re choosing to do that something.  That sucks for you, but hey – at least now you know that either you, or the subject matter, are not important.  It’s not warm and fuzzy information to know about that person, but now this creates that same choice – for you – to stop wasting your time on a person or subject matter that doesn’t really matter.

So, Yes, people are staring at their phones.  And it’s the best thing they could be doing.  It may hurt your feelings, but the reality is that we now have more opportunities than ever to focus on the things that really matter to us, and I couldn’t be happier about it.

Related Posts Plugin for WordPress, Blogger...

Continue Reading