Should services always return DTOs, or can they also return domain models?

it doesn’t feel right when domain model leaves business layer (service layer) Makes you feel like you are pulling the guts out right? According to Martin Fowler: the Service Layer defines the application’s boundery, it encapsulates the domain. In other words it protects the domain. Sometimes service needs to return data object that wasn’t defined … Read more

Using MySQL with Entity Framework [closed]

It’s been released – Get the MySQL connector for .Net v6.5 – this has support for [Entity Framework] I was waiting for this the whole time, although the support is basic, works for most basic scenarios of db interaction. It also has basic Visual Studio integration. UPDATE http://dev.mysql.com/downloads/connector/net/ Starting with version 6.7, Connector/Net will no … Read more

Entity Framework Core add unique constraint code-first

On EF core you cannot create Indexes using data annotations.But you can do it using the Fluent API. Like this inside your {Db}Context.cs: protected override void OnModelCreating(ModelBuilder builder) { builder.Entity<User>() .HasIndex(u => u.Email) .IsUnique(); } …or if you’re using the overload with the buildAction: protected override void OnModelCreating(ModelBuilder builder) { builder.Entity<User>(entity => { entity.HasIndex(e => … Read more

Entity Framework and Connection Pooling

Connection pooling is handled as in any other ADO.NET application. Entity connection still uses traditional database connection with traditional connection string. I believe you can turn off connnection pooling in connection string if you don’t want to use it. (read more about SQL Server Connection Pooling (ADO.NET)) Never ever use global context. ObjectContext internally implements … Read more

Decimal precision and scale in EF Code First

The answer from Dave Van den Eynde is now out of date. There are 2 important changes, from EF 4.1 onwards the ModelBuilder class is now DbModelBuilder and there is now a DecimalPropertyConfiguration.HasPrecision Method which has a signature of: public DecimalPropertyConfiguration HasPrecision( byte precision, byte scale ) where precision is the total number of digits … Read more

What does principal end of an association means in 1:1 relationship in Entity framework

In one-to-one relation one end must be principal and second end must be dependent. Principal end is the one which will be inserted first and which can exist without the dependent one. Dependent end is the one which must be inserted after the principal because it has foreign key to the principal. In case of … Read more

Non-static method requires a target

I think this confusing exception occurs when you use a variable in a lambda which is a null-reference at run-time. In your case, I would check if your variable calculationViewModel is a null-reference. Something like: public ActionResult MNPurchase() { CalculationViewModel calculationViewModel = (CalculationViewModel)TempData[“calculationViewModel”]; if (calculationViewModel != null) { decimal OP = landTitleUnitOfWork.Sales.Find() .Where(x => x.Min … Read more

Unique Key constraints for multiple columns in Entity Framework

With Entity Framework 6.1, you can now do this: [Index(“IX_FirstAndSecond”, 1, IsUnique = true)] public int FirstColumn { get; set; } [Index(“IX_FirstAndSecond”, 2, IsUnique = true)] public int SecondColumn { get; set; } The second parameter in the attribute is where you can specify the order of the columns in the index. More information: MSDN