Navigation Property without Declaring Foreign Key

I believe, it is not possible to define the relationship only with data attributes. The problem is that EF’s mapping conventions assume that Creator and Modifier are the two ends of one and the same relationship but cannot determine what the principal and what the dependent of this association is. As far as I can … Read more

Self referencing / parent-child relationship in Entity Framework

You must define the ParentId in the category class as nullable to use it as the foreign key property for an optional relationship: public int? ParentId { get; set; } An int property cannot take the value null and therefore cannot represent a NULL as value in a database column.

How can I stop Entity Framework 5 migrations adding dbo. into key names?

You can customize the generated code by sub-classing the CSharpMigrationCodeGenerator class: class MyCodeGenerator : CSharpMigrationCodeGenerator { protected override void Generate( DropIndexOperation dropIndexOperation, IndentedTextWriter writer) { dropIndexOperation.Table = StripDbo(dropIndexOperation.Table); base.Generate(dropIndexOperation, writer); } // TODO: Override other Generate overloads that involve table names private string StripDbo(string table) { if (table.StartsWith(“dbo.”)) { return table.Substring(4); } return table; } … Read more

where is context.Entry()?

may be too late to answer but it may help others, EF 4.0 uses the ObjectContext class where as the version 4.1 uses the DbContext class in which the methods like Set<T> and Entry are defined. With version 4.0 you can do something like DatabaseContext _context = new DatabaseContext(); _context.ObjectStateManager.ChangeObjectState(entity, System.Data.EntityState.Modified); with version 4.1 its … Read more

Entity Framework 1 to 1 relationship using code first. how?

This occurs in CodeFirst because of the virtual keyword. In effect, you are creating a relationship where creating one item requires the creation of the other. however, the virtual keyword allows lazy instantiation, which means that creating an object of one type doesn’t automatically create the other type, allowing the Id on the foreign item … Read more

BeginTransaction with IsolationLevel in EF Core

The EF Core code is exactly the same. DbContext.Database.BeginTransaction(IsolationLevel.Snapshot); The only difference is that in EF Core the method with isolation level (as many others) is an extension method, defined in RelationalDatabaseFacadeExtensions class, and importantly, located in Microsoft.EntityFrameworkCore.Relational assembly. So if you have using Microsoft.EntityFrameworkCore; and don’t see it, add reference to the Microsoft.EntityFrameworkCore.Relational.dll assembly … Read more

Ignore TransactionScope for specific query

If you wrap your log call inside of another transaction scope with the suppress option enabled, transaction scope will not be used. public override int SaveChanges() { try { return base.SaveChanges(); } catch (Exception ex) { using (var scope = new TransactionScope(TransactionScopeOption.Suppress)) { LogRepo.Log(message); // stuff to log from the context } throw; } }

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