entity-framework-core

Cannot use table 'AspNetUsers' in schema '' for entity 'AspNetUsers' since it is being used for another entity

女生的网名这么多〃 提交于 2019-12-02 08:00:29
问题 We are trying to add Identity 3 to our existing Customers app by extending AspNetUsers public class ApplicationUser : IdentityUser { public string BusinessName { get; set; } public string ContactName { get; set; } public string CountryCode { get; set; } public virtual Countries Country { get; set; } public string AddressLabel { get; set; } public string Phone { get; set; } public DateTime? FollowUp { get; set; } public bool MailingList { get; set; } public int SubscriptionId { get; set; }

When using Scaffold-DbContext for UWP I get 'Unable to load DLL 'sqlite3''

左心房为你撑大大i 提交于 2019-12-02 07:51:17
问题 I am trying to scaffolf an Entityframeworkcore DbContext for a UWP app from a Sqlite databse. I do: Scaffold-DbContext "data source=C:\SqliteDbFiles\Sqlite.db" Microsoft.EntityFrameworkCore.Sqlite No matter what I try though I keep getting this error: System.DllNotFoundException: Unable to load DLL 'sqlite3': This operation is only valid in the context of an app container. (Exception from HRESULT: 0x8007109A) at Microsoft.Data.Sqlite.Interop.NativeMethods.Sqlite3_sqlite3.sqlite3_open_v2

Entity Framework Core Use Include on QueryType(Database View)

陌路散爱 提交于 2019-12-02 07:49:30
问题 I have EF Core connected to MySql and I have a View called: PostViews I read this article saying I can use Query Types for Database Views. It works if I just call _context.PostViews, but if I use Include on it like: _context.PostViews.Include(xxxx), it throws me this error: System.InvalidOperationException: 'The property 'Comment' is not a navigation property of entity type 'PostWithViews'. The 'Include(string)' method can only be used with a '.' separated list of navigation property names.'

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

大憨熊 提交于 2019-12-02 07:41:31
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> : IContextFactory<T> : where T : DbContext { public T CreateDbContext(string connectionString) { var

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

房东的猫 提交于 2019-12-02 07:24:57
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 ICollection<Product> Products { get; set; } } public class ShopContext : DbContext { public ShopContext

Listbox for MVC 6 EF 7 Property not Populating

送分小仙女□ 提交于 2019-12-02 07:00: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 Reproduce Issue Create a new ASP.Net Web Application → Name of project: ListBox.Web → Name of solution

Which one must I use, MyDbContext.Blogs.Add(ablog) or MyDbContext.Add(ablog)?

好久不见. 提交于 2019-12-02 06:43:35
Consider I have a context MyDbContext inherits DbContext of EFCore 2.0. Blogs is a DbSet<Blog> and Blog is an entity model. When I add a new Blog instance, ablog to the Blogs , which one must I use? MyDbContext.Add(ablog); or MyDbContext.Blogs.Add(ablog); ? How about Find ? MyDbContext.Find<Blog>(1); or MyDbContext.Blogs.Find(1); ? Is there any benefit to use one over the other one? Adding directly data via the DbContext is new to the DbContext in Entity Framework Core and have no equivalents in previous version of Entity Framework where the DbContext is available (i.e. EF 4.1 onwards). But

EF Generic Repository Multiple Includes

僤鯓⒐⒋嵵緔 提交于 2019-12-02 05:18:37
问题 Idea is to have one Generic Repository which will work with all entities. I managed that, but if I need to have method which should include one or more other entities there is a problem for me. I have put some idea in code, but that is not working for me. Also I have been thinking to use aggregate function in EF, but that I have never use. Can someone give me direction how I can manage this ? public interface IRepository<T> where T : BaseEntity { IEnumerable<T> GetAll(); T Get(Int64 id); void

AspNet EF referencing foreign key to field

…衆ロ難τιáo~ 提交于 2019-12-02 04:57:34
问题 Im having two models: public class Customer { public int Id { get; set; } public int Number { get; set; } public int ParentNumber { get; set; } public string Name { get; set; } public string Address { get; set; } public string City { get; set; } public string Country { get; set; } public string Language { get; set; } } and public class Batch { public int Id { get; set; } public int Number { get; set; } public string FileName { get; set; } public string ArticleNumber { get; set; } public

aspnet core entity framework 7 self referencing “job” 1 to many table

吃可爱长大的小学妹 提交于 2019-12-02 04:54:40
I have a "Job" table that contains jobs. The fact is Jobs are not always done in one go.. you can have a job that has many visits. I intended to represent that as another job but linked back to the original job via self referencing linkId. I am having trouble representing this using the fluent API. Its a one to many relationship.. one job might have many visits and thus a number of linkId's point back to the orginal job. The link Id would back to the orginal job Id. Its also optional since most jobs might be completed in one go.. I have looked for this but its difficult to turn the other