entity-framework-6

Entity Framework Cascade delete - FOREIGN KEY constraint

烈酒焚心 提交于 2019-12-22 10:53:22
问题 I have a problem with the following model: public class ProjectPage { [Key] public Guid Id { get; set; } public Guid? HeaderId { get; set; } public ProjectPage Header { get; set; } public Guid? FooterId { get; set; } public ProjectPage Footer { get; set; } } On model Creating I have this: modelBuilder.Entity<ProjectPage>().HasOptional(p => p.Header).WithMany().HasForeignKey(p => p.HeaderId).WillCascadeOnDelete(true); modelBuilder.Entity<ProjectPage>().HasOptional(p => p.Footer).WithMany()

How to make ASP.NET Core RC2 app build on net46 framework with older third party dependencies

时光毁灭记忆、已成空白 提交于 2019-12-22 10:05:21
问题 I have a shiny new Asp.Net Core MVC App that references some older net45 libraries. Works fine with Asp.Net Core RC1 on full net45 framework. Migrating from Asp.NET Core rc1 to rc2 I have hit an obstacle that I don't know how to fix. The App is a ASP.NET Core App that using EF6, Autofac, Kendo.MVC and it needs to run on the full .Net 4.6 framework as there are references libraries that use WCF. In migrating from rc1 to rc2 I first update the NuGet.config feed to point to https://www.myget.org

How can i return a dataReader using Entity Framework 6.1?

混江龙づ霸主 提交于 2019-12-22 09:56:46
问题 Exactly as the question asks. I am using entity framework for most of my code, but i also need to execute and return a count or columns from a sql table that is not within my entity framework context. 回答1: You can run a raw query using Entity Framework, for example: using (var context = new BloggingContext()) { var blogNames = context.Database.SqlQuery<string>( "SELECT Name FROM dbo.Blogs").ToList(); } If you want to return a more complex type, you can define your own class and use that

How to define a one to one self reference using Entity Framework Code First

一个人想着一个人 提交于 2019-12-22 08:51:10
问题 I want to implement versioning on my entity Stuff . Each entity has an optional reference to the next version (the latest version will be null) and an optional reference to the previous version (the first version will be null). I am using entity framework 6, code first. I tried with the following model and modelbuilder statement (and many variations). public class Stuff { public int StuffId { get; set; } [ForeignKey("NextVersion")] public int? NextVersionId { get; set; } [InverseProperty(

How to cancel an async query the right way

喜你入骨 提交于 2019-12-22 08:15:21
问题 This is a follow up question to this question. I'm trying to load data from my database which will take 5-10 seconds, but I want the GUI to stay responsive and also it should be cancellable. private CancellationTokenSource _source; public IEnumerable<Measurement> Measurements { get { ... } set { ... } } private async void LoadData() { _source = new CancellationTokenSource(); using (var context = new TraceContext()) { Measurements = null; Measurements = await context.Measurements.ToListAsync(

MySql Connector with EF 6

眉间皱痕 提交于 2019-12-22 07:06:30
问题 I am having a weird issue with MySql Connector(6.8.3) and EF6. I was working on a WebApi project where I use MySql and EF6 with Database first approach. Everything worked fine[even deployed on one of the test servers] until I changed the database from 'Test' database to 'Production' database [just the database name] in the connection string and updated the model[just to see nothing is broken!]. After that, it failed to connect to database. So, I changed the connection string back and rebuilt

How to access context after each Entity Framework db migration

别说谁变了你拦得住时间么 提交于 2019-12-22 05:34:13
问题 When I Add-Migration, I get the appropriate DbMigration class with the Up / Down methods, where I am able to make schema changes and (with the use of the Sql() method) can make data/content changes as well. I'd like to be able to make content changes per migration using the database context. I understand that I could use the Seed method in a Configuration class, but my understanding is that I can only wire up one Configuration with my initializer. I'd prefer to have a UpCompleted()

Non Clustered Primary Key Entity Framework Code First

[亡魂溺海] 提交于 2019-12-22 05:10:08
问题 In Entity Framework Code First approach, can we define the Primary Key as non-clustered index and a combination of few other fields as clustered index. Thanks 回答1: EntityTypeConfiguration does not provide a means of setting the Primary Key as a non-clustered index, but you can complete this by altering the initial migration used for table creation. There is an example here. Here is an example of how to specify a clustered multiple-column index using attributes: [Index("IX_ColumnOneTwo", 1,

The difference between EF6 and EF4.1 in files hierarchy

梦想与她 提交于 2019-12-22 04:39:20
问题 I'm a beginner to Entity Framework . I notice that When I use EF6 with Visual studio 2013 : I have .Designer.cs empty file with this comment: // T4 code generation is enabled for model 'C:\Users\Luka\Desktop\Test\EF-db2008\AdventureWorks\AdventureWorksLib\AdventureWorksLib\AWLTModel.edmx'. // To enable legacy code generation, change the value of the 'Code Generation Strategy' designer // property to 'Legacy ObjectContext'. This property is available in the Properties Window when the model //

How can I get Glimpse to work with EF6?

不想你离开。 提交于 2019-12-22 04:16:06
问题 EDIT : stack trace added at bottom. I have an ASP.NET MVC 5 project that uses a SQL Server database via Entity Framework 6. I added Glimpse (and Glimpse.MVC5) to the project, and that works fine. However, when I add Glimpse.EF6, my application throws an exception as soon as it attempts to access the database. The exception is: System.NotSupportedException Unable to determine the provider name for provider factory of type 'System.Data.SqlClient.SqlClientFactory'. Make sure that the ADO.NET