Entity Framework, Code First and Full Text Search

Using interceptors introduced in EF6, you could mark the full text search in linq and then replace it in dbcommand as described in http://www.entityframework.info/Home/FullTextSearch: public class FtsInterceptor : IDbCommandInterceptor { private const string FullTextPrefix = “-FTSPREFIX-“; public static string Fts(string search) { return string.Format(“({0}{1})”, FullTextPrefix, search); } public void NonQueryExecuting(DbCommand command, DbCommandInterceptionContext<int> interceptionContext) { } … Read more

How do I singularize my tables in EF Code First?

You’ve removed the wrong convention (PluralizingEntitySetNameConvention) for this purpose. Just replace your OnModelCreating method with the below and you will be good to go. using System.Data.Entity.ModelConfiguration.Conventions.Edm.Db; … protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Conventions.Remove<PluralizingTableNameConvention>(); } With Entity Framework 6, on your file that inherit from DbContext: using System.Data.Entity.ModelConfiguration.Conventions; protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Conventions.Remove<PluralizingTableNameConvention>(); … Read more

MapKey vs HasForeignKey Difference – Fluent Api

Both mappings will create exactly the same database schema with a non-nullable foreign key SomethingId and a referential constraint between the two related tables. The first mapping with MapKey is used when you don’t want to have the foreign key as a property in your model class. The type of association in this case is … Read more

Improve navigation property names when reverse engineering a database

There a few things you need to change inside the .tt file. I choose to use the third solution you suggested but this requires to be formatted like FK_CollectionName_RelationName. I split them up with ‘_’ and use the last string in the array. I use the RelationName with the ToEndMember property to create a property … Read more

EF 6.1 Unique Nullable Index

I didn’t find a way to tell EF to use this where clause but here is some workaround. Check if it fit in your case. Install Entity Framework, Define your DbContext, entities, conn string in app.config etc. Enable Migration – run in Package Manager Console ‘-EnableMigration’ Create DbMigration – run in Package Manager Console ‘Add-Migration … Read more

EF Core Error – No project was found. Change the current working directory or use the –project option

sometimes you need to change the current directory in console/terminal eg: PM> cd E:\Projects\CrossTest\ PM> dotnet ef migrations add InitialMigration and Align your package versions. Either use preview1 packages or preview2. Mix of those are not supported.