Geeks With Blogs

News Please visit me at my new blog!!

profile for Aligned at Stack Overflow, Q&A for professional and enthusiast programmers
"free in Christ Jesus from the law of sin and death." Romans 8:2 (ESV) Check out the Falling Plates video on YouTube.
more about the Gospel
And then listen to Francis Chan speaking at LifeLight in SD.

Programming and Learning from SD Entity Framework
Databases in Continuous Delivery
I enjoyed listening to Databases in Continuous Delivery with Enrico Campidoglio on .Net Rocks and learning about tools to do CD with databases. I’ve looked at how to have the database schema in source control so that you can rebuild your database at a moments notice for different environments. The options we’ve came across as a team have included Database Projects In Visual Studio, Code First Migrations with Entity Framework, manually creating the scripts using Visual Studio’s data compare tools ......

Posted On Wednesday, January 21, 2015 5:00 PM

Use the NotMapped Attribute with Entity Framework in Partial Classes
I wanted to add a property to send to my JavaScript class through WebApi, but didn’t want it in the database. I was getting an error telling me I had an invalid name on the EF 5 selection from the database. Adding the NotMapped attribute to the property did the trick. I get it on the JavaScript side as well. I found the answer (again) on StackOverflow. Example: public partial class ComponentAttribute { [NotMapped] public bool IsModified { get; set; } } ......

Posted On Wednesday, May 15, 2013 4:32 PM

Here’s why the Unit of Work is needed
I didn’t understand why I would want to use the Unit of Work pattern before I ran into this. I had a ManagerBase class that had an IRepository. (The managers implement ManagerBase which have a private Repository that follows Juans approach Repository had the context and saveChanges method. This means that each “Manager” I had, contained a different instance of the context. This ......

Posted On Tuesday, March 12, 2013 4:21 PM

Set the DateModified in the Repository
I have database tables that have DateCreated and DateModified as DateTime types. I was getting the error (“The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.”) when I tried to save through the context.SaveChanges() for Entity Framework. First I added GetGETUTCDATE() to the default of the column in the database. Then in my Repository Update Method, I used reflection to set the DateModified property. public void Update(T entity) { var entry = this._context.Entry(entity); ......

Posted On Thursday, January 10, 2013 4:01 PM

Quick Test for Entity Framework DBContext

A co-worker wrote this and we think it is useful.

Posted On Friday, December 28, 2012 2:41 PM

Mocking or Faking DbSet
I needed to Fake the DbSet of a DBContext in EF 5 so that I could test my caching implementation. I searched for awhile and found this link on creating an in memory DbSet. I first copied the code in and created an InMemoryDbSet class. Then I changed all my DbSets in my DBContext to IDbSet. Then I was able to mock the call to UserProfiles and return a dummy object. The Test I’m using FakeItEasy which is a nuget packages. Notice the usage of the InMemoryDbSet<UserProfil... [TestInitialize] public ......

Posted On Wednesday, December 12, 2012 11:14 AM

Get a new instance with StructureMap
It took me too long to figure this out, so hopefully it will help you. StructureMap has way that will create a new instance of the object every time, instead of storing this in the container. I’m going to use this for the DBContext and for WCF Service references. Since the ObjectFactory is a static class, MVC will have these stored in memory without this. Credit goes to Joshua Flanagan for answering my question.[TestMethod] public void GetConcreteInstanceOf_Shoul... { ObjectFactory.Initialize(re... ......

Posted On Thursday, November 29, 2012 10:44 AM

Copyright © Aligned | Powered by: