Entity Framework, Navigation Properties, and the Repository Pattern

Generic Repository vs Non-generic Repository Generic repository is not a pattern. Generic repository is just a wrapper. It can be useful for some special scenarios as a base class for specific repositories but in most cases it is just over used and over hyped nonsense. Navigation properties Repository itself should be used with aggregate root. … Read more

What effect do the different EF 4 SaveOptions have on the ObjectContext?

Short correction for SaveOptions.DetectChangesBeforeSave : this is the default. When you do ObjectContext.SaveChanges(), the method DetectChanges() is called to synchronized attach entities in the OSM. SaveChanges is an overloaded version of SaveChanges(SaveOptions optsions) method, where this parameterless version calls this SaveChanges(SaveOptions.DetectChangesBeforeSave | SaveOptions.AcceptAllChangesAfterSave) SaveOptions is a Flag enum and in conclusion, SaveOptions.DetectChangesBeforeSave | SaveOptions.AcceptAllChangesAfterSave is … Read more

Primary /Foreign Key in Entity Framework

I think by “not using EF ORM designer” you mean new DbContext API from EF 4.1. Because if you don’t mean DbContext API you still have to use EDMX (designer). You can either use data annotations (System.ComponentModel.DataAnnotations): KeyAttribute and ForeignKeyAttribute: public class Registry { public virtual int Id { get; set; } public virtual MyEntity … Read more

Could not load file or assembly Oracle.DataAccess

In the IIS Manager select your server and select “Application Pools“. Select the application pool used by your Web App and click on “Advanced Settings” from the right hand menu. In the “General Section” of the advanced Settings click on the “Enable 32-bit Applications” and set it to True. This fix only applies to 64-bit … Read more

Entity Framework Code First Lazy Loading

This is wrong “virtual” keyword is used for not loading the entities unless you explicit this (using an “Include” statement) Lazy Loading means that entities will be automatically loaded when you first access collection or navigation property, and that will happen transparently, as though they were always loaded with parent object. Using “include” is loading … Read more

Modify default ErrorMessage for StringLength validation

You can specify the StringLength attribute as follows on numerous properties [StringLength(20, ErrorMessageResourceName = “StringLengthMessage”, ErrorMessageResourceType = typeof(Resource))] public string OfficePhone { get; set; } [StringLength(20, ErrorMessageResourceName = “StringLengthMessage”, ErrorMessageResourceType = typeof(Resource))] public string CellPhone { get; set; } and add the string resource (named StringLengthMessage) in your resource file “Maximum length is {1}” Message … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)