entity-framework-core

DataAnnotation Atributes not applied in EF7

自闭症网瘾萝莉.ら 提交于 2019-12-25 01:08:31
问题 When i migrate a database using k ef migration add bla bla. command the data annotation attributes are not reflected to the created database e.g. iam using the [MaxLength(2)] attribute and am getting a column with data type nvarchar(MAX) created Any help please 回答1: Data Annotations are not yet implemented in EF7. See issue #107. 来源: https://stackoverflow.com/questions/27924491/dataannotation-atributes-not-applied-in-ef7

Does DbContext need MemoryCache or Redis in Net Core?

て烟熏妆下的殇ゞ 提交于 2019-12-25 01:07:19
问题 We have multiple lookup tables in a SQL Server database. Tables are used in application dropdown menus. AddressType: Home Business ProductType: Books Food Electronics Instead of continually reading database lookup tables, team wants to apply MemoryCache or Redis Cache (to reduce database load, and increase in-memory performance). However, we learned that Entity Framework Core DbContext already has caching. So in this case, would there be any value in caching looking tables, if after a certain

Pomelo.EntityFrameworkCore.MySQL DBContext throwing “Unqualified data type char” exception

寵の児 提交于 2019-12-25 00:55:26
问题 I am trying to port an existing application from EF 6 and MySQL.Data.Entity.EF6 to EF Core and Pomelo.EntityFrameworkCore.MySql. When the DBContext creates its model, it throws an ArgumentException with message "Unqualified data type char." I can reproduce the error in a brand-new Console project. As soon as I add a DBSet<Site> to my DBContext, where Site is a class from my existing project's Database.Entities dll, the validation error appears. Abbreviated stack trace: at Pomelo

Entity Framework Core get context in console application

半城伤御伤魂 提交于 2019-12-24 21:04:35
问题 I have a Visual Studio 2017 solution with 3 projects. One class library that has DAL (.NET Standart 2.0), one AP.NET MVC Application (.NET Core 2.0) and the third Console Application (.NET Framework 4.6.1). I have referenced DAL in both of the projects. It has implemented Unit of Work pattern and uses Entity Framework Core. In ASP.NET MVC project I have configured to get context with Dependency Injection as follows services.AddDbContext<ApplicationDbContext>(options => { options.UseSqlServer

Entity Framework Core - Error inserting many-to-many relation

99封情书 提交于 2019-12-24 21:04:23
问题 I use Entity Framework Core 2.0.1 and the goal is to insert some many-to-many related objects in the DB by an auxiliar entity. However, I get the error: " The instance of entity type 'ReferenciaFabricanteTieneReferenciaConstructor' cannot be tracked because another instance with the key value 'IdReferenciaConstructor:0, IdReferenciaFabricante:0' is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached. ". I guess that

Columns with data-type prefix cause “Type X is not a defined system type” error

好久不见. 提交于 2019-12-24 20:28:17
问题 I'm working with a 3rd party database. Usually queries that I write in LINQPad and later translate to Entity Framework Core (2.1) work without any issues. However, not this time. When I try to use the column Status I'm getting the following SqlException : Class 16 byte LineNumber 1 int Message "Type Enumeration is not a defined system type." string Number 243 int Procedure "" string Server "..." string Source ".Net SqlClient Data Provider" string State 2 byte so I opend the SQL Server

EF Core, configure modelBuilder to fix error “cycles or multiple cascade paths”

馋奶兔 提交于 2019-12-24 20:13:25
问题 I want to configure folowing relations: Like may has a Reason (type Comment) and this Comment have to be cascade deleated if Like will be deleated Like may have a Comment (type Comment) or User (type User), Like have to be cascade deleated if Comment or User will be deleated Like must not have both Comment (type Comment) and User (type User) Author (type User) must not be able to create Likes duplicates I tried many combinations but did not have a success, please help me. My current code:

How to update a list of multiple records same as normal SQL Update query using entity framework core?

别说谁变了你拦得住时间么 提交于 2019-12-24 19:33:52
问题 Normally in SQL we can write this query UPDATE users SET isAdult = 1 WHERE age >18 I want to apply some edit to all rows that satisfy some condition in entity framework core. I wrote this code and I got an error List<User> usersList = _context.Users.Where(u => u.age >18).ToList(); usersList.ForEach(a => { a.isAdult = 1; }); _context.Entry(usersList).State = EntityState.Modified; _context.SaveChanges(); The error is System.InvalidOperationException: The entity type 'List' was not found. Ensure

Model for child table is always null in the partial view

痞子三分冷 提交于 2019-12-24 19:18:56
问题 In my ASP.NET Core 1.1 , EF-Core 1.1 app , I'm displaying data in a parent view that has partial view . Scenario is similar to the following: one-to-many relationship between Customers and Orders table . User selects a customer from a dropdown in the Parent View that has a partial view that displays corresponding orders for the selected customer. But, I'm always getting model passed to the Partial view always null. Question : What I may be missing here? Note : By placing breakpoints, I've

Invalid Object Name error when creating database with EF Code First

巧了我就是萌 提交于 2019-12-24 19:15:32
问题 Hello i am developing a database using EF Core Code First .I keep getting this error when generating the database : Microsoft.EntityFrameworkCore.DbUpdateException: 'An error occurred while updating the entries. See the inner exception for details.' InnerException {"Invalid object name 'Parents'."} System.Exception {Microsoft.Data.SqlClient.SqlException} From what i have read it seems i can not create the database because the tables are somehow pluralized. I have searched for solutions