Entity framework PostgreSQL
Entity framework also works with Npgsql – .Net Data Provider for Postgresql. A tutorial on how to set it up can be found here: http://www.npgsql.org/ef6/index.html
Entity framework also works with Npgsql – .Net Data Provider for Postgresql. A tutorial on how to set it up can be found here: http://www.npgsql.org/ef6/index.html
Try this: var sql = @”Update [User] SET FirstName = @FirstName WHERE Id = @Id”; ctx.Database.ExecuteSqlCommand( sql, new SqlParameter(“@FirstName”, firstname), new SqlParameter(“@Id”, id));
In fact this is two questions in one: When should I Dispose() of a context? What should be the lifespan of my context? Answers: Never 1. using is an implicit Dispose() in a try-finally block. A separate Dispose statement can be missed when an exception occurs earlier. Also, in most common cases, not calling Dispose … Read more
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
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
I had the same issue and the cause was a POCO class that had a property of type Type.
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
Just don’t use Entity Framework in this case. Just use a stored procedure (how to depends on the version/approach you use with EF, you might will have to extend your DbContext or add a mapping from the entity model). If you’re using SQL Server, then in your store procedure, do use the MERGE command that … Read more
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
There is no default configuration for eager loading. You must always define Include or create some reusable method which will wrap adding include. For example you can place similar method to your context: public IQueryable<MyEntity> GetMyEntities() { return this.MyEntities.Include(e => e.SomeOtherEntities); }