entity-framework

Configure multiple database Entity Framework 6

删除回忆录丶 提交于 2020-01-09 04:38:49
问题 In my solution I have 2 projects that use Entity Framework 6. Each points to a different database, both using the same data provide - SQL Server. A third project in my solution needs to use both databases. My problem is how to configure those context. I tried to create a configuration class in a separate assembly: namespace OSAD_Base { class EfDbConfiguration : DbConfiguration { public EfDbConfiguration() { SetProviderServices(SqlProviderServices.ProviderInvariantName, SqlProviderServices

How to remove child one to many related records in EF code first database?

大憨熊 提交于 2020-01-09 04:14:06
问题 Well, I have one-to-many related model: public class Parent { public int Id { get; set; } public string Name { get; set; } public ICollection<Child> Children { get; set; } } public class Child { public int Id { get; set; } public string ChildName { get; set; } } What I want to do is clear Parent.Children and remove related child entities from database. I've already tried: Database context class: modelBuilder.Entity<Parent>() .HasMany(p => p.Children) .WithOptional() .WillCascadeOnDelete(true)

Could not load file or assembly Microsoft.Extensions.DependencyInjection.Abstractions, Version=1.1.0.0

不想你离开。 提交于 2020-01-09 03:45:04
问题 After update to the new package Microsoft.EntityFrameworkCore.SqlServer 1.1.2 I got error when try to create DBContext: System.IO.FileLoadException occurred HResult=0x80131040 Message=Could not load file or assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=1.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) Source

Could not load file or assembly Microsoft.Extensions.DependencyInjection.Abstractions, Version=1.1.0.0

此生再无相见时 提交于 2020-01-09 03:44:04
问题 After update to the new package Microsoft.EntityFrameworkCore.SqlServer 1.1.2 I got error when try to create DBContext: System.IO.FileLoadException occurred HResult=0x80131040 Message=Could not load file or assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=1.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) Source

'datetime2' error when using entity framework in VS 2010 .net 4.0

大憨熊 提交于 2020-01-08 19:41:14
问题 Getting this error: System.Data.SqlClient.SqlException : The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value. My entity objects all line up to the DB objects. I found only a single reference to this error via Google: Google result After reading this, I remember that we did add 2 fields and then updated the entity model from VS 2010. I'm not sure what he means by "hand coding" the differences. I don't see any. All I'm doing in code is populating

'datetime2' error when using entity framework in VS 2010 .net 4.0

我怕爱的太早我们不能终老 提交于 2020-01-08 19:41:12
问题 Getting this error: System.Data.SqlClient.SqlException : The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value. My entity objects all line up to the DB objects. I found only a single reference to this error via Google: Google result After reading this, I remember that we did add 2 fields and then updated the entity model from VS 2010. I'm not sure what he means by "hand coding" the differences. I don't see any. All I'm doing in code is populating

How can I return a list of rows of dynamic table? [duplicate]

℡╲_俬逩灬. 提交于 2020-01-07 08:36:12
问题 This question already has answers here : DataTable iteration gives unwanted data (2 answers) Anonymous type result from sql query execution entity framework (5 answers) Closed 5 days ago . My previous question was closed due to typo. But my issue is unresolved. So rephrasing the question. Hi, I have a query which returns data dynamically. Number of columns, their name and datatypes are not known. It's like a Select * from table_name I need to get the result in a list. I tried with IEnumerable

MVC 5 ASP.NET Entity Framework Collect Form Data through Range Input

让人想犯罪 __ 提交于 2020-01-07 07:59:13
问题 So I am creating a survey monkey, a Survey Has 4 categories, and each category has 5 questions, the HomeController Index passes on the 20 questions from the Questions entity and each Questions must have a Range Slider with values from one to 5, the form values must be collected into a method in the controller, then accumulated into the QuestionResults table and processed, then they must be passed onto the CategoryResults and each Category, out of the 4, must have an accumulated score, they

EF4: NavigationProperty and join: is a bug or a feature?

前提是你 提交于 2020-01-07 07:47:08
问题 I’d like to consult about a problem I have faced. I've started working on a project with a very difficult database: many tables in the DB don’t have primary keys or have multiple PKs, so I can't add correct associations for all entities in my edmx. However, for some entities it’s possible and I managed to do so. Thus, I have two entities with an association between them: Vulner and VulnerDescription. And I have a "bad" connection table for Vulners called VulnerObjectTie (with a mental FK:

ApplicationDbContext Seed starts only if I go to Person Controllers index action in ASP .NET MVC 5.1 application

泪湿孤枕 提交于 2020-01-07 07:09:08
问题 I run the Web Application HomeController.Index() action is run. Then I go to Person.Index() (it is at the bottom of this post) via browser then and only then Migrations.Configuration.Seed() is invoked. But I want it to happen at the application start. Configuration: namespace WebApplication2.Migrations { using Microsoft.AspNet.Identity; using Microsoft.AspNet.Identity.EntityFramework; using System; using System.Collections.Generic; using System.Data.Entity; using System.Data.Entity.Migrations