entity-framework-6

Is it correct if i am using await + ToListAsync() over IQueryable which is not define as a task

血红的双手。 提交于 2019-12-17 20:18:31
问题 I am using asp.net MVC-5 with EF-6, and I am not sure if using await + ToListAsync is valid. For example, I have the following repository method which returns an IQueryable :- public IQueryable<TSet> getAllScanEmailTo() { return t.TSets.Where(a=>a.Name.StartsWith("ScanEmail")); } And I am calling it as follow:- var emailsTo = await repository.getAllScanEmailTo().ToListAsync(); In the beginning, I thought I will get an error because I am using "await" a method which is not defined as a task,

EF6 two contexts vs. single context with two awaits

有些话、适合烂在心里 提交于 2019-12-17 19:56:55
问题 Which of these is a better approach for performance? Note: For some operations I have up to five independent queries to execute. var foo = await context.foos.ToListAsync(); var bar = await context.bars.ToListAsync(); vs. var fooTask = context1.foos.ToListAsync(); var barTask = context2.bars.ToListAsync(); await Task.WhenAll(fooTask , barTask); It would be great to use the same context without awaits, but this answer mentions that is not possible. 回答1: As you found out, the DbContext is not

Creating a double linked list in Entity Framework

老子叫甜甜 提交于 2019-12-17 19:39:38
问题 I have an object which can optionally have a reference to a next and/or previous record. Something like this: public class Foo { [Key] public int Id {get; set;} [ForeignKey("Previous")] public int? PreviousId {get; set;} public Foo Previous {get; set;} [InverseProperty("Previous")] public Foo Next {get; set;} } Unfortunately this does not work, instead resulting in the error message Unable to determine the principal end of an association between the types Foo and Foo . The idea is that by

Code first custom SQL migration timeout exception

老子叫甜甜 提交于 2019-12-17 19:12:19
问题 I am trying to create FULL TEXT index using Entity Framework Migration by executing custom Sql. My migration class looks like this: public partial class DocumentContentFullTextIndex : DbMigration { public override void Up() { AlterColumn("dbo.Attachments", "ContentType", c => c.String(maxLength: 260)); Sql("CREATE FULLTEXT CATALOG FullTextIndexes AS DEFAULT;", true); Sql(@"CREATE FULLTEXT INDEX ON [Attachments]( Content TYPE COLUMN ContentType Language 'ENGLISH' ) KEY INDEX [PK_dbo

No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'.

我的未来我决定 提交于 2019-12-17 18:45:55
问题 We are using EntityFramework 6 with Code First. We have a console app that has no reference to EntityFramework but reads the connection string from its App.config. It calls the DatabaseInitializationUtilities assembly passing the connection string as a parameter. DatabaseInitializationUtilities has the reference to EF6 (EntityFramework and EntityFramework.SqlServer). Its App.config is this: <?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <!-- For more information on

ASP.Net Identity - Use custom Schema

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-17 15:44:56
问题 I am using MVC5 + Ef6 code first with ASP.Net Identity 1.0 and wish to have the tables created in a custom schema. i.e. a schema that is not the dbo schema. I reversed engineered my databse using the Ef power tools and set the schema name for all other tables in the mapping class to the following this.ToTable("tableName", "schemaName"); I tried doing this for the ASP.Net tables but it kept giving me a lots of errors and eventually I gave up. If I exclude the (reverse engineered) ASP.Net

EF6 and multiple configurations (SQL Server and SQL Server Compact)

梦想的初衷 提交于 2019-12-17 15:39:23
问题 Update: Problem solved, see end of this question. The problem : We are trying to use Entity Framework 6 and code-based configuration in a scenario were we have use both a SQL Server and SQL Server CE in the same AppDomain . This quite simple scenario seems not to be supported "by design". From the EF team: Note: We do not support having multiple configuration classes used in the same AppDomain. If you use this attribute to set different configuration classes for two contexts an exception will

SQLite EF6 programmatically set connection string at runtime

折月煮酒 提交于 2019-12-17 15:37:48
问题 I try to migrate form EF 3.5 to 6 (with SQLite as database). We can not set the connection string in the app config file (this works without problems with ef6). We have to set connection string programmatically at runtime (after user has selected the SQLite file). Here is our app.config <?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> <section name=

Entity Framework 6: Clone object except ID

倖福魔咒の 提交于 2019-12-17 15:36:04
问题 In my MVVM program I have a Model class (say MyModel ) from which I have an instance of reading from the database (using Entity Framework). When retrieving the object I'm presenting all the data to the user. Later on the user will be modifying some fields. What I want is to create the same object except for it's ID (since that ID is the primary key and auto incremented ). So how could I approach this? I don't want to copy all fields one by one, this is not a robust approach. Because perhaps

Upgrade from Entity Framework 5 to 6

二次信任 提交于 2019-12-17 15:26:10
问题 After upgrading our project from using Entity Framework 5 to Entity Framework 6 (though NuGets update function) i get the following error on my generated Entities class: Error 1 The type or namespace name 'Objects' does not exist in the namespace 'System.Data' (are you missing an assembly reference?) I understand that this is because the namespace has changed and i can manually fix the error by changing my imports from: using System.Data.Objects; and using System.Data.Objects.DataClasses; To: