entity-framework-core

C# Dotnet core - Issues with implementing generic DBContext in constructor

时光总嘲笑我的痴心妄想 提交于 2019-12-02 15:08:54
问题 I am struggling with this coming back from a long layoff. I asked a question regarding the configuring of a DBContext in my generic base repository. Only after a user has logged in can I then construct a connection string so I cannot register a service in startup.cs - I have to use a constructor argument to instantiate my DBContext. I got this answer which I thought would address the problem however I am getting an error in the following factory class: public class ContextFactory<T> :

Can I stop Entity Framework Core from populating my result with partial data?

白昼怎懂夜的黑 提交于 2019-12-02 13:13:41
On this page of the Entity Framework Core documentation, it says when querying loaded data: Entity Framework Core will automatically fix-up navigation properties to any other entities that were previously loaded into the context instance. So even if you don't explicitly include the data for a navigation property, the property may still be populated if some or all of the related entities were previously loaded. This is true whether it is Eager or Explicit . I find this to be frustrating, because it will return partial data, which makes it seem like a complete list because there's nothing

EF Core defeats the purpose of constructor with null checking

不想你离开。 提交于 2019-12-02 12:40:01
I have designed my models so that it should not be created with a null parameter. For example, if I want to enforce that every Post should have a corresponding Blog , then my models will look like: public class Post { private Post() { } public Post(Blog blog) { Blog = blog ?? throw new ArgumentNullException(nameof(blog)); } public int PostId { get; private set; } public Blog Blog { get; private set; } } public class Blog { public int BlogId { get; private set; } } This way, it will throw an Exception if blog is null . But I use EF Core and it fails this test. public class Tests { [Fact] public

Entity Framework Core on Windows IoT running on a RPi 3 (Console Application)

妖精的绣舞 提交于 2019-12-02 11:47:15
问题 I successfully deployed a .NET Core Console Application to my Windows IoT running on a Raspberry Pi 3. The application pulls data from a webservice and stores them in a database. I used Entity Framework Core for that. When I start the deployed console application (.exe) through the remote powershell everything works except the access to my database running on Azure. When the application tries to read from the database it throws the following exception: System.TypeInitializationException: The

EntityFramework 7 with Azure Table Storage provider code samples

南楼画角 提交于 2019-12-02 11:23:55
问题 Looking for some code samples of EF7 with Azure Table Storage provider 回答1: The Azure Table Storage provider was a prototype and will not be supported by EF Core until after 1.0. See https://github.com/aspnet/EntityFramework/issues/1142 Also note, the ATS provider was removed from the EF Core project in 2014. It has not been updated since. 来源: https://stackoverflow.com/questions/34943317/entityframework-7-with-azure-table-storage-provider-code-samples

ef core one to many relationship throw exception Cannot add or update a child row

丶灬走出姿态 提交于 2019-12-02 10:48:23
问题 My Shop and Product entities have a one to many relationship, please see my models public class Product { public int ID { get; set; } public string Name { get; set; } public string Tag { get; set; } public string Brand { get; set; } public string Place { get; set; } public int ShopID { get; set; } public Shop Shop { get; set; } } public class Shop { public int ID { get; set; } public string Name { get; set; } public string Comment { get; set; } public string Number { get; set; } public

Entityframework core 2.0 how to map Many-to-Many without creating a join table

久未见 提交于 2019-12-02 10:26:29
I am trying this activity to clone from existing .edmx project to code first. I have two entities. I want to have many to many relation without creating a new table. I am using EF Core 2.0 code first approach. Please find below the entity i have created. I am not sure whether is this is the right way to do this. I would like to have the foreign key column on both the tables ie. WorkflowId and WorkCaseId on WorkCase and Workflow tables respectively. public class WorkCase { [Key] public int WorkCaseId { get; set; } public int WorkflowId { get; set; } public int CaseDetailId {get;set;} public

Entity Framework ChangeTracker Stream and Save to Query Afterwards

那年仲夏 提交于 2019-12-02 09:37:19
I want to validate when certain Entity is Modified/Updated/Inserted/Deleted in Entity Framework (with database). (eg ProductType Entity table) ** Would like Change Tracker to be saved and queried later, as 'the track changes are lost if they are not saved before the DbContext object is destroyed.' Only need ChangeTracker to be retained for couple hours most to analyze, and be saved in MessageQueue if needed. MemoryCache can also work. 1) Someone recommend using LoggerFactory: optionsBuilder.UseLoggerFactory(loggerFactory) https://www.entityframeworktutorial.net/efcore/logging-in

Automapper Projection with Linq OrderBy child property error

…衆ロ難τιáo~ 提交于 2019-12-02 09:31:40
问题 I am having an issue using an AutoMapper (version 5.1.1) projection combined with a Linq OrderBy Child property expression. I am using Entity Framework Core (version 1.0.0). I am getting the following error: "must be reducible node" My DTO objects are as follows public class OrganizationViewModel { public virtual int Id { get; set; } [Display(Name = "Organization Name")] public virtual string Name { get; set; } public virtual bool Active { get; set; } public virtual int OrganizationGroupId {

Listbox for MVC 6 EF 7 Property not Populating

为君一笑 提交于 2019-12-02 08:48:00
问题 I've been trying for a while now to get a list box to populate and I can't seem to figure it out. I've studied entity framework 7 documentation pretty extensively but I'm still new to it. There aren't a lot of tutorials out there for MVC6/EF7 yet so its been hard to know what the best practice is for associating one entity class with an instance of another. Please excuse the length of the question, I'm just trying to be thorough. I'm using entity framework 7, asp.net 5 and MVC 6. Steps To