entity-framework-6

Linq to Entities, Inject Join Inside Query Expression

限于喜欢 提交于 2019-12-25 00:37:10
问题 I'm trying to improve the performance for some of our LINQ queries and there is one little thing that has a lot of space for improvement: joins. Almost all my queries have some join that is used to filter the result, but are not selected into de result. And these filtering conditions are optional... What I have today is something like: var q = from t1 in context.Set<T1>() where t1.mandatoryfilter >= 0 select t1; if (useFilter) { var q2 = from t1 in q from t2 in context.Set<T2>().Where(t2 =>

How to recover from Entity Framework nightmare - database already has tables with the same name

我只是一个虾纸丫 提交于 2019-12-24 21:00:29
问题 How do you get EF back in Sync with code without losing data when Update-database returns the following message Error Message: System.Data.SqlClient.SqlException (0x80131904): There is already an object named '' in the database. 回答1: I originally wrote this as a self-answering question as I had struggled with the proble for some time, as had a few colleagues, but unfortunately, my answer was deleted and I can't recover it. Since it's a situation that I suspect can happen several times as

Enitity Framework Each property name in a type must be unique

孤街浪徒 提交于 2019-12-24 19:04:44
问题 I have the following entities defined and the relationship mapping also. However, while saving i get the error Name: Each property name in a type must be unique. Property name 'ResponseId' is already defined. in EF 6 System.Data.Entity.ModelConfiguration.ModelValidationException I am struck with this for 2 days and not sure, what is the issue in my class. If I remove, ResponseId in ResponseOffer, it is working fine. However, I need to set this value to save it in the database and its FK

ExpressionTree method to Assign MemberInitExpression to property

假装没事ソ 提交于 2019-12-24 18:22:11
问题 I am trying to use expression trees so that I can choose to map across to a DTO using entity framework in much the same way as the Include directive works on a DbSet (part of an open sorce project implementing OData). The code below represents a test case. Expression<Func<Bar, Bar>> mapBar = b => new Bar { BarInt = b.BarInt, BarString = b.BarString }; Expression<Func<Foo, Foo>> mapFoo = f => new Foo { FooInt = f.FooInt, B = null }; Expression<Func<Foo, Foo>> target = f => new Foo { FooInt = f

Enity Framework 6.0.0.0 : Unable to generate an explicit migration… with Code-based migration

徘徊边缘 提交于 2019-12-24 17:24:11
问题 The situation is : Per tenant db. Non-automatic Code-based based migration. The initial creation of the dbs is through Code First too. There are no preexisting dbs in the current scenario. The exact db is not known during the generation of migration script becase there are many. The only thing I have is code - the Initial migration script based on the model in the beginning and the model with some modifications. Existing dbs generated with initial script - everything works fine. Here is how I

Enity Framework 6.0.0.0 : Unable to generate an explicit migration… with Code-based migration

风格不统一 提交于 2019-12-24 17:23:04
问题 The situation is : Per tenant db. Non-automatic Code-based based migration. The initial creation of the dbs is through Code First too. There are no preexisting dbs in the current scenario. The exact db is not known during the generation of migration script becase there are many. The only thing I have is code - the Initial migration script based on the model in the beginning and the model with some modifications. Existing dbs generated with initial script - everything works fine. Here is how I

Entity Framework 6 DBContext disable delete option

一个人想着一个人 提交于 2019-12-24 14:26:45
问题 Anyone please help me on how to disable DELETE option in EF6? I mean from the application, now record should be deleted (even accidentally) Thanks. 回答1: Create a user/role in the database that does not have permissions to delete/modify records and use it in your application. EF itself is not meant to be a security tool and there are always options to perform a delete operation (e.g. a developer can send any arbitrary SQL query/command to the database bypassing all the 'security' measures

ASP.NET MVC 5 Entity Join

末鹿安然 提交于 2019-12-24 13:42:56
问题 I'm new in ASP, Entity and lambda expressions. How can I join two tables? Route Model: public partial class Route { public Route() { Flights = new HashSet<Flight>(); } public int RouteID { get; set; } public int DepartureAirportID { get; set; } public int ArrivalAirportID { get; set; } public int FlightDuration { get; set; } public virtual Airport Airport { get; set; } public virtual Airport Airport1 { get; set; } public virtual ICollection<Flight> Flights { get; set; } } Airport Model:

Entity Framework 6.1: How to change clustered index to another column?

*爱你&永不变心* 提交于 2019-12-24 13:42:35
问题 I have an entity like this: public class Invoice { public Guid Id { get; set; } public int InvoiceNumber { get; set; } public string Caption { get; set; } } In my mapping file, I set the clustered index on InvoiceNumber and set a non-clustered index on the Id column. public class InvoiceMapping : EntityTypeConfiguration<Invoice> { public InvoiceMapping() { HasKey(p => p.Id).Property(e => e.Id).HasColumnType(SqlDbType.UniqueIdentifier.ToString()).IsRequired() .HasColumnAnnotation("Index", new

EntityFramework (6) and async ( waitingForActivation)?

[亡魂溺海] 提交于 2019-12-24 13:26:23
问题 I've downloaded EF6 ( in order to use async ) So I wrote this simple method : public async Task<List<int>> MyasyncMethod() { var locations = await MyDumpEntities.AgeGroups.Select(f=>f.endYear).ToListAsync(); return locations; } ...Later... DumpEntities1 MyDumpEntities = new DumpEntities1(); var data = MyDumpEntities.AgeGroups.ToListAsync(); MyasyncMethod().ContinueWith(s => { Response.Write("f"); }); MyDumpEntities.Dispose(); But I don't see anything on the screen and when I inspect data I