Uncategorized
Entity Framework – It’s the little things…
by Andrew Tobin on Aug.18, 2010, under Uncategorized
So I have been working with Entity Framework for a short time on a sekrit projekt at the moment and even just with my beginner experience, and very limited need for special features, I keep running into issue points, so I thought I’d enumerate some here.
Now, for reference, I am using Entity Framework 4, CTP4 aka Magic Unicorn Edition.
1. Guid Primary Keys with Clustered Indexes.
You can probably find a lot of guidance online about why you don’t want Guids in a clustered index, but the basics are that with a clustered index, it tries to keep the index sorted, and Guids by their very nature are random.
So what you’re doing is, every time you insert or delete a row into your table, using an object that has an ID with a type Guid, it makes the SQL server work to find the right place to do the insert, puts the row in, and then has to re-sort the index to be correct.
The correct behaviour would be to keep it as Primary Key, so the Guid/uniqueidentifier is unique, but to have a non-clustered index – which means the key is still indexed, it can still find the key quickly and efficiently, but it doesn’t make the server work to keep it sorted in order.
The way it stands now, the Clustered Index will cause severe performance issues when as the amount of data in your database increases.
I have listed a Microsoft Connect article here to fix the issue.
The guidance I got from one of the team was to include some DDL scripting to drop and recreate the index, or make my own EF Provider, as a wrapper around their provider, to do the table creation properly – but I would like to see them fix this, as most of us would just accept what Microsoft are doing as correct.
2. The ability to Exclude properties from mapping to the Database.
Say for example, I have a property that I require in my object model for the view – say I want to collect the user’s email address, so I can create a Gravatar string (which is an encrypted hash of the email address) and then just save the string in my database, and not have to store their email anywhere.
Well, at the moment, whatever is in my object model will get mapped to the database (and if I allow it, Entity Framework will automatically create the database table with the email address in it.
There seems to be two ways around this at the moment:
1) Create the property with no setter, so it is read only.
2) Create the mappings by hand.
In the first instance, I cannot populate the address from the view, which makes it unusable, and in the second, I would have to manually map the other 40 properties, in code, and make sure I remember to update or map any future changes and additions.
The alternative would be for them to add another attribute, so I could do something like:
[Exclude]
public string EmailAddress { get; set; }
As far as things go, it’s a difficult learning process, as most guidance out there seems to be around the older way of doing Entity Framework, using model-first or at least the model designer.
I would love to see more information on dealing with POCO classes and the CTP4 out there, in an more centralised fashion, through the group’s blog or some better screencasts.
For example, finding information about how to change the schema prefix from “dbo” to your own, in EF seems impossible – I have a few ideas to try, but at the moment, it’s not the easiest framework to get into for a n00b.
I’ll possibly update this post as other issues come up, but if you have any suggestions on how to get around some of these problems, that I’ve overlooked – feel free to leave them, or links to helpful resources in the comments.
SQL Down Under Code Camp 2009
by Andrew Tobin on Oct.10, 2009, under Uncategorized
We entered slightly late and unfortunately they changed around the timing of Rob Farley’s presentation and the CSU Masters program, probably under the correct assumption that everyone would want to skip the CSU masters and see Rob’s.
REALLY ANNOYING.
Mostly because it’s true and that we missed half of Rob’s presentation – which was as awesome and energetic and helpful as always. He also seemed to be doing most of his presentation from the SQL Management Studio – which if you can see Rob working within the studio environment – he flies and is really great at giving examples.
And then we had to sit through the sell.
I got us onto the network – but of course then my pc failed and I got kicked off the network and can’t rejoin – so the CSU wireless network hasn’t changed over the last two or three years – as useless as always.
And then we have Julia Heather with Database Mirroring which we have zero interest in and won’t be employing in work – she seems enthusiastic and people seem to be enjoying it, asking questions so I guess it’s valuable to someone in the room
She also didn’t do much that wasn’t in powerpoint and the slides are pretty packed – so it’s tough for me to care – plus the slides had a company branding on the bottom which is kind of… yeah.
Right now – still a bit annoyed I can’t get online as I could be liveblogging this or doing twitter and enjoying the backchannel – which has become the best part of the codecamp experience.
Really. CSU Networking team FAIL. (And EPIC FAIL because this isn’t the first year this problem that has occurred).
Managed to get on back on the network by putting this URL into a browser (even when I couldn’t get the CSU homepage: https://networks.csu.edu.au/cgi-bin/netdirect_conf.pl
And we’re back on the backchannel – twitter hashtag #sducc09
Now listening to Greg Low who is going over indexing and going a little bit more into the depths of the technology than I need, would prefer to just see the stuff working, best practice etc.
Also, I feel like I saw this exact talk at SQL Code Camp last year – so many of the talks seem to be repeated every year or that might just be my perspective.
I just have this feeling that someone didn’t show and Greg had to do a filler or something and this happened. Or I am just confused.
Anyway, it’s an alright talk – something everyone needs to know – how to index properly. Not much to say – it seemed to go on a bit, lot of anecdotes going into it.
THIS POST WILL UPDATE AS THE DAY CONTINUES
Rob Farley’s Lobsterpot Solutions Training Courses
by Andrew Tobin on Oct.10, 2009, under Uncategorized
This past week we had Rob Farley of Lobsterpot Solutions out to give our company’s development team Analysis Services training and it was pretty brilliant.
Rob is a SQL MVP and an expert on Analysis Services and came to us in rural NSW, for a few days to go over what we would need to do to make a data warehouse, use analysis services cubes, and perform things like Data Mining.
He based the training off the Microsoft course on Analysis Services, but went ten steps further in providing real world knowledge and examples, and taking our scenarios of working within a farming system and really trying to understand and use our domain to further our education.
All three days he was great in the training, happy to go further into other topics like profiling, t-sql and performance tuning, indexing, backups and other topics where we needed further help or education – and was great at answering every question.
And he was able to give a view on any question or scenario we gave him.
He also went one step further in explaining not only how we’d achieve something, but to make sure we kept out internal customers needs in mind – and explaining how they’d achieve what they need, and how they can access data better.
He was also more than willing to come to our local Albury/Wodonga .NET User Group and give a talk while he was in the area – and he gave a brilliant talk on T-SQL tips that really blew everyone away. Tips and information that we’d never heard of, that was incredibly well presented and received.
I’d have no problems recommending Rob’s training or help to anyone – it really was some of the best training I have ever received and we’re now in a position where we’ve got tonnes of ideas on how we’re going to use the training to improve so much of how our company works.
Why the User Group is Good For Me
by Andrew Tobin on Aug.20, 2009, under Uncategorized
Recently our local user group has had a bit of a break period – it’s relatively small and we had all burnt out a bit – especially those of us who are constantly presenting.
We returned last month, to basically an intro C# video fest, but it’s got me a little introspective.
I think the best times I have had to learn recently is when I have been cramming to learn something enough to pass on a somewhat educated review at the user group.
I won’t say I’ve learnt anything in depth that I’ve presented – even LINQ I feel like I’m swimming in the shallows of it, but that’s all I have needed day-to-day at work, and in contrast to the guys who don’t get to develop with these tools often, I do feel slightly more advanced.
So what I am thinking of doing, and blogging to at least get it down to motivate me – is to learn a topic a month. Choose some technology I have been hearing about, and devote enough time that I’d be happy to present some of the basics of it, over the course of a month.
That’s not to say I wouldn’t be learning other things – but I’d try to devote a bit of blog space, actually blog the links and sources I use online and discuss things in more detail.
Anyway, that’s the plan, so I’ll start with the new month!
Any suggestions?
The LiveAutographs.Com Experience – LOST Event Review
by Andrew Tobin on May.05, 2009, under Uncategorized
A while ago I ran across a Techcrunch article which seemed kind of nifty – a startup that was doing live video autographs!
Well, I have people I have to buy presents for – so I decided to give it a shot, and although there wasn’t a huge range I did see some of the LOST stars were up there and so I decided to get an autograph for a friend who is as much into LOST as I am.
That was around 6 months ago, and the LOST event just happened recently so I thought I’d give some feedback on the experience.
Firstly, I signed up for a video autograph by Matthew Fox, paid, ordered the extra dvd to come with it so that we could keep that as well and waited.
Basically we went for a couple of months without hearing a thing before I contacted them to get some feedback on when they thought the event might take place – their blog is pretty sparse on details too but it seems that they don’t do anything regular, but wait until they have enough orders and an opportunity to run a session… it also seems like they don’t actively promote sessions coming up in order to try and fill them quicker.
So basically the feedback after the first couple of months was nil, and when I heard it was basically a note saying don’t expect to hear from us too soon – expectations were reset, and you can understand it must be difficult to run these things.
It was also at this time that I found out the event had changed to become a sponsorship to a cancer charity, so you can’t exactly complain when your money is going to a good cause.
Two months later (around Jan) I received a new email apologising for the delay and saying that the item that I’d ordered to be signed (a LOST poster) was being updated to the current seasons promotional gear – more than happy with that. Great to hear that nothing has been abandoned and it was still on the go.
End of March I get another email – basically filming delays in Hawaii has changed the event and they can no longer do the video and gave me the option of three choices – a signed poster by the cast, a video message from Damon Lindelof and Carlton Cuse, or my money back.
Fair enough, I went for the poster – hey, I’m not only getting one signature, I’m getting now eleven, and it’s turned from a unique, one of a kind gift to one of 75 in a set.
Also, disappointing is to lose the video which is the reason for the service, the differentiation and losing the personal side of it… but what are you going to do?
It was going to be signed by: Matthew Fox, Evangeline Lilly, Josh Holloway, Henry Ian Cusick, Jorge Garcia, Daniel Dae Kim, Yunjin Kim, Michael Emerson, Elizabeth Mitchell, Terry O’Quinn, Ken Leung.
Just as an aside – here’s some spoilers for LOST for you – now that the event has taken place, funnily enough Charlotte and Daniel have died recently, which explains why Ken Leung (Miles) was the only new cast member on the list, and Sayid has disappeared in the jungle which is why he wasn’t – which is disappointing.
Anyway, the package finally arrived and we opened it, and it turned out not to be the poster at all – which is a shame, because we could have mounted it and hung it and it would have been AWESOME – but a copy of the Pilot script, which is difficult to work out what you’d do with that as memorabilia, even though the pilot of LOST is also awesome (and kind of funny to have so many characters who weren’t in the first few seasons signing it!)
So we got the script and a certificate of authenticity saying that the eleven actors had really signed it – which is ironic because, again, the reason for the service is that it’s more believable than any old certificate of authenticity to actually see the actors signed it.
There was no personalisation whatsoever, either, which is a shame.
But, I can honestly say that it’s a unique gift – because when we looked at it, only ten out of the eleven actors had actually signed it!!
Looking through the scrawls it looks like Terry O’Quinn must have missed it – dude, Locke! Damn it! I’m always on Terry O’Quinn watch – he was on The West Wing, Alias, The X-Files Movie! Millennium! So it’s another big disappointment hoping he’d sign and then not getting that either.
Anyway, this is turning into a bit of a rant of disappointments… but I have to say, they were upfront the whole time – a little uncommunicative, but what is there to say other than they tried their best to put together an event, when they couldn’t deliver they made it clear and offered a full refund – and in the end we still ended up with a pretty nice piece of memorabilia?
Would I do it again? Hm… probably, if it was the right people – I mean I know my nephew would kill for someone like John Cena, and anything Joss Whedon I would jump at – so yeah, if those sorts of celebs were doing this sort of thing I would possibly take the chance.
Again, even though there were set backs and disappointments, and it took a while to get there – the guys from LiveAutographs.com were upfront and open as things happened, offered refunds or options and you really can’t ask for more than that I guess!
Hope that helps, if you’re looking to use them!
KISS -> Finding a better way
by Andrew Tobin on Jan.30, 2009, under Uncategorized
Everyone should know now that KISS is Keep It Simple Stupid, but basically I was working away on a project at work and what we needed was a graphical line chart that displayed the growth based on user input, to give them some visual feedback of the curve they were entering.
I started very complexly using Stack and LinkedList, making my own methods to validate and add and remove segments so that the whole thing would work cohesively, and then it was pointed out to me that we didn’t really need to take into account both ends of each segment, we might as well just treat it as the next segment takes its start from the last.
So I simplified my objects all the way back to a simple list and a validator on submit – but that left how was I going to do the graphing?
It’s in a winforms .NET application, so I thought maybe there was a graphing library, or I could use lines and the drawing primatives, but I needed some values on the axis and all that.
Anyway, had a quick think and came up with the ReportViewer control! We already use Reporting Services for a lot of our reporting and the users are familiar with that, but I’d never done it with an in-memory set of data, using the local version.
Half an hour later I had a spiked test version done and ready for smoothly bringing it back into the main project. Seriously, I had visions of such complexity, for something that could resolve itself so easily, and the boss had no qualms about using that control in the production application.
Sometimes you just need to take a step back and stop banging your head on the desk long enough for the ideas to come through to you – and remember to keep things as simple as possible and they’ll often work.
Which Path Do You Follow?
by Andrew Tobin on Jan.29, 2009, under Uncategorized
Reading this post by Davy Brion raised a few thoughts in my head, and I thought I’d put them here.
Davy talks about who you pay attention to for guidance in becoming a better .NET developer – the Microsoft experts, the Alt .NET and community experts, finding other places – what is the best direction to head.
In the end he comes up with use your own judgement, common sense can guide you.
I agree with that, but I generally do follow blogs, listen to ideas that bubble up over and over, if I hear about patterns or practices that someone recommends then I go and Google it, research it.
Generally, if someone’s willing to pay for a book for it to be made, and if people are willing to buy it, then it’s worth a look at the ideas in there. I’d pay attention to topics that show up on places like Dot Net Rocks, Hanselminutes, Codebetter, Los Techies, screencasts around the place.
Basically, anyone willing to put ideas forward in a public forum, have the conversation and go through the wringer.
And then, like Davy recommends, I’d choose the parts that make sense to me and try them out – generally you find out pretty quick if you’re headed down the wrong path.
That being said, for me, I’m mostly following my manager
It helps to have a cohesive architecture, and as well, to paraphrase something Robert Scoble once wrote:
“I’m following thousands of people, reading tens of thousands of pieces of information a day and talking to industry leaders, who do you read?”
“You.”
For all the things I read and come across, my manager does as well, and I find if we are generally talking to each other about topics that interest the both of us then it’s generally something that’s worth a bit more research.
I think the best way you can find the right path is to find someone else as interested in learning as you are, get to a .NET User Group, or see what the community leaders are interested in – but do your own research.
Architecture by User Fear
by Andrew Tobin on Jan.28, 2009, under Uncategorized
A funny topic came up today at work that I thought I’d share.
We’ve been working on a project for the better part of the year and been really optimistic with it, even though there’s been false starts on it previously, and the users have only been interested in it from the point of view of “it’d be nice to have but it’s creating work for me”.
We’ve gotten it deployed to a couple of users for testing and they’ve been slow to get interested in actually doing that, but we went ahead with one today and it’s making us second guess a decision.
We have certain events that something can perform on a product, such as adding elements – now we decided from the start that we were going with an optimistic view, so that you could only add events to the queue.
So, lets say we create a product, and then we do an addition to it – but we accidentally add to the wrong product – what would you do? Well, we made it so that you could adjust that product, so that you could take it back to the original state.
But in the history of that product it would record that, and we can report on the adjustments made.
The first time the user struck that, day 1 of testing, and he was horrified – he didn’t want to adjust and took that as the wrong way to progress – because his adjustment would be seen by one of the bean-counters in accounting and that would be seen as a very negative thing to him.
So we’re back to the drawing board on having to redo all our objects, or rather the events, to undo and wind back changes – which means a minor re-architecture.
And this guy was in all the architecture meetings, made the decisions with the others, and we had discussed the way things were going to be adjusted.
I don’t know what we take away from this, but I still think we went down the right path because we ended up with a fairly beautiful and efficient user story, for the interface and the processes – we were just a tad too optimistic about what they would accept on the perception of when things went the wrong way!
Some Goals for this Year
by Andrew Tobin on Jan.27, 2009, under Uncategorized
Just to document some things I’d like to achieve this year, unless I completely forget or other priorities take over
1. After having listened to the last couple of Hanselminutes episodes I’d like to study a bit more on the current architecture standards coming through the .NET community. The shows I am referring to are:
- Show 140 – Rob Conery on Domain Driven Design
- Show 145 – SOLID Principles with Robert C. Martin
- Show 146 – Test Driven Development with Scott Bellware
Basically, all these three shows have got me back into being interested in hearing more Hanselminutes (I chose the shows to listen while driving for a trip), but more than that they resonated with what we’re already trying to do, or to achieve at work.
For instance, although we probably don’t really follow DDD, we do have a pretty tight cohesion to the companies domain, terminology, and processes. A lot of what Rob Conery said actually applies to how we try to go about our software development, with the planning and dialogue we open with our users.
So the interest there would be to study a bit more of the practice of DDD, and maybe not taking the practice to heart and keeping to every principle, or pattern – but see what we’re already doing that works similar to the framework and what practices related to that we could adopt that would make sense.
Similarly, listening to Scott Bellware on Test Driven Development, although we are writing tests semi-first (I tend to unless I am having a hard time wrapping my head around some code, in which case I spike then wrap tests), I came to realise I’m probably under-thinking TDD/BDD.
My methods are coming out much like they would if I didn’t test, with overly complex tests – not simplified enough for it to be proper TDD.
Now that is kind of the way the boss wants it and the way we adopted it, but I don’t know if I’d call us a TDD shop (and I don’t think he would either, even if we are a testing shop – we work for a private company and are efficient and producing quality code anyway, so it’s kind of semantics for us).
The thing I don’t think I do enough of is considering the behaviour, or the aspect of what a method is trying to achieve before I code it up. I mean, I understand I want to get from A-to-B with this method, I want it to achieve X reason for existing – but I don’t frame that in “for this unit of work, this is how the guys on the floor are using this, and this is the process it would go through, so the method should behave accordingly.
I honestly don’t think it’s that far of a leap from where I am now with my thought patterns, but it’s about taking that time to work that flow instead of thinking of it as purely code that achieves a function and tests that will prove that code does that function.
2. Become basically familiar with another language, either Ruby or probably Python. This isn’t learning something so I can use it on a daily basis to a high degree – but just learning it for readability, become familiar enough so I understand what other developers are talking about, and just learn the basics for interest.
3. Read more code. I’m pretty insular or isolated with the code that I am doing, and I do things my way and it works, but I think I need to get back to listening to podcasts, watching the rest of Rob Conery’s MVC Storefront series, and just get a better idea to improve my own development.
4. Prepare for meetings better. Hopefully I won’t be attending that many meetings in the future, but I had the thought the other day that I walk into a lot of meetings with not much idea of what to say, and I end up being in a situation where I can be caught unprepared or put on the spot, or am just reacting.
So the idea here is to push more for an agenda for any meeting I’m attending, to come with some idea of what I’m going to say, some planned points on paper, and to try and stick to the topic – there’s nothing more that I hate than a meeting that is just all general business of whatever anyone can think of at the time, and I find a lot of the “Monday morning scheduled meetings” that occur weekly for everyone to catch up, generally, just meander unprepared and anyone will bring up whatever is on their minds at the time.
5. Self-manage better. We have Fogbugz at work, but it’s a personal productivity tool, and if you don’t use it, it’s not really enforced. That’s fair, but I do know I work better when I have a list of tasks in front of me, when I can cross things off and feel like I’m achieving things.
The past year while I had a project that kept my interest I’d find that I’d do the next two-four weeks scheduled work within the first few days, because I was driven, interested, and had a plan of what I had to achieve.
I have to find a good balance of spending time setting up and managing myself, so I am more productive in the other times, rather than spending all my time trying to just work and get through things, and either be caught out by things I haven’t done, things that I haven’t done timely enough, or finding myself with time that I just don’t have enough to do because I haven’t scheduled enough into my time.
There’s probably more I should be doing, but those things came to the top of my mind while driving home from my trip and I think they’re a good start!
Another Day in the Workplace
by Andrew Tobin on Jan.26, 2009, under Uncategorized
Recently I was travelling for work and taking the opportunity to be a bit social and ask around if there was any way I could help the guys in the remote office.
There are several people in the main office that I ask now and again if there is anything I can do, as their IT Dev, to make their lives easier.
Now people seem to hate the idea of their lives being easier – they somehow equate my helping streamline their jobs as me making them less required, which for the most part is never true – there is always more work or more opportunities for the time that you can save.
So, if I ever asked one particular guy if there was any process he could think of for me to streamline something he’s involved with, he’s always said no – no real need.
Well, it turns out one of the guys in the remote office puts together, weekly, a report that he has to get the data from the system, add in costings, take from two other reports figures, format and send to the guy at the main office.
All in all, it probably takes him an hour of working on, and I wouldn’t be surprised if it took three hours of mucking around and corrections and other communication issues.
And all that could be replaced with a report directly from the main system that would take 10 seconds, and could be automatically emailed each week directly to the main office without any interaction or activity from the remote office.
It’s funny how you can perceive that an activity wouldn’t need streamlining when it only takes you a minute to read the email, but like an iceberg – under the surface, it’s taking someone else hours.
I guess the morale to the story is that I need to get round to the guys out there more and get their lay of the land, because what you see from your office isn’t the whole story.