combination of two field must be unique in Entity Framework code first approach. how it would?

Checking for duplicates means you have to go to the database to validate. In Entity Framework Code First, that means using the DbContext. See Implementing Validation in the Context with ValidateEntity for a great explanation of how to validate in Entity Framework. You should override the ValidateEntity method in your context class: protected override DbEntityValidationResult … Read more

PropertyGrid Browsable not found for entity framework created property, how to find it?

Using ICustomTypeDescriptor is definitely the good solution when you want dynamic (set at runtime) properties. Here is generic ICustomTypeDescriptor utility class that I’ve been using for this sort of property grid hacking, it’s pretty straightforward to use: public sealed class DynamicTypeDescriptor: ICustomTypeDescriptor, INotifyPropertyChanged { private Type _type; private AttributeCollection _attributes; private TypeConverter _typeConverter; private Dictionary<Type, … Read more

ef core 2 apply HasQueryFilter for all entity

In case you have base class or interface defining the IsActive property, you could use the approach from Filter all queries (trying to achieve soft delete). Otherwise you could iterate entity types, and for each type having bool IsActive property build dynamically filter expression using Expression class methods: foreach (var entityType in modelBuilder.Model.GetEntityTypes()) { var … Read more

How do I map a char property using the Entity Framework 4.1 “code only” fluent API?

Char is not valid primitive type for entity framework = entity framework doesn’t map it. If you check CSDL reference you will see list of valid types (char is not among them). Database char(1) is translated as string (SQL to CSDL translation). Char is described as non-unicode string with fixed length 1. The only ugly … Read more