January 15th, 2012EntityFramework CodeFirst and AutoKey Generation
This one had me a little stumped, and as usual, there are not enough examples in the Microsoft documentation to be very helpful. I’m using EntityFramework CodeFirst with Visual Studio 2011. Let’s assume you create a class as follows:
public class CongressNumber { [Key] public int CongressNumberValue { get; set; } }
Then, you manually set the value of CongressNumberValue to 112. I’d certainly think that is a reasonable thing to do. I know that the Microsoft guys often special case Id or id, but hard to believe they would take something like CongressNumberValue and assume I meant that to be an autogenerating Identity column. Well, it seems they do that and the doc’s don’t even mention it.
After first, finding the page on annotations, I discovered that what we really need to set is this to have it work as we want (with no identity key generation).
public class CongressNumber { [Key] [DatabaseGenerated(DatabaseGeneratedOption.None)] public int CongressNumberValue { get; set; } }
I found this after drilling down some in there doc. What surprises me is that no where does it mention that if you have a string, that does not get database generated, but if you have an int, that does. I wonder what happens if you have a Guid? (I’ll leave that up to someone who wants to use a guid).
I would have loved to put in my own comments on the page: http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.databasegeneratedoption(v=vs.103).aspx but there was no user comment section. Oh well.
To be fair, on the page: http://msdn.microsoft.com/en-us/library/gg197525(v=vs.103).aspx it does explain about identity and integers but when I had my issue, I was already on the detail page. Seems to me the detail page should have more information on it than the summary page that leads in. The only reason I found it was because while writing this post, I went back to get the proper links.
HTH’s.









March 23rd, 2012 at 7:57 pm
Hello Chris, I agree with you, mozy is good, and much better than other backup products in the market like carbonite, we all do remember carbonite lost their customers data in 2009!! and they blamed it on hardware, but I still prefer a real online backup using pure cloud, like Amazon, it’s much better and I know my data secured and replicated (Risk is there but lesser than proprietary storage), I don’t like the idea of storing my data with a proprietary online backup like mozy, I wanted to backup my office, mozy is good, but not real business solution, it’s very expensive when it comes to business ($0.50 per GB), and the cloud management is fine, but still lacks some stuff, the other solutions (like Carbonite, Durva, crashplan) are big joke for a real business solution, no real cloud console, they are not business solutions at all, I found a good cloud solution it’s called Timeline Cloud, still testing it, but seems business oriented, complete cloud Disaster recovery which is cool and complete mobile access, I think it’s worth reviewing