NOT using repository pattern, use the ORM as is (EF)

I’ve gone down many paths and created many implementations of repositories on different projects and… I’ve thrown the towel in and given up on it, here’s why. Coding for the exception Do you code for the 1% chance your database is going to change from one technology to another? If you’re thinking about your business’s … Read more

Insert data using Entity Framework model

It should be: context.TableName.AddObject(TableEntityInstance); Where: TableName: the name of the table in the database. TableEntityInstance: an instance of the table entity class. If your table is Orders, then: Order order = new Order(); context.Orders.AddObject(order); For example: var id = Guid.NewGuid(); // insert using (var db = new EfContext(“name=EfSample”)) { var customers = db.Set<Customer>(); customers.Add( new … Read more

Entity framework EF.Functions.Like vs string.Contains

Like query supports wildcard characters and hence very useful compared to the string extension methods in some scenarios. For ex: If we were to search all the 4 lettered names with ‘ri’ as the middle characters we could do EF.Functions.Like(c.Name, “_ri_”); or to get all the customers from cities which start with vowels: var customers … Read more