entity-framework-core

How do I configure other user defined data-type with Entity Framework Core?

强颜欢笑 提交于 2019-12-11 02:23:19
问题 I'm using scaffolded entities with Entiy Framework Core 2.1. The 3rd party database uses some unser defined data types (that I didn't know about) that don't seem to be recognized by EF-Core. According to The Fluent API HasColumnType Method and Reverse Enginer: Support type aliases (user-defined data types) this should work. However, I'm not sure if only for precofigured/built-in types like Name or any types. The engine generates this entity.Property(e => e.Status).HasColumnType("Enumeration")

Get rows that come alphabetically after one with a specified ID

断了今生、忘了曾经 提交于 2019-12-11 02:04:58
问题 I'm using .NET Core 1.1, EF Core 1.1. I have a Category object that I'm querying to do pagination. My function receives the ID of the last object that the front-end parsed, then I need to get the next X objects. I'm sorting alphabetically, however, and I'm not sure how to get the objects that come alphabetically after the object with the given ID. For example, let's say I have this in my DB: ID | Name ---|----- 1 | Sports 2 | Music 3 | Books 4 | TV Shows For simplicity, we'll say I only want

Why does EF Core always return -1 with this stored procedure?

北城余情 提交于 2019-12-11 01:55:13
问题 I am trying to use EF Core (latest release) against a Local 2016 DB and I am getting -1 back every time. I don't know what I have done wrong? I know that it is reaching the database. I checked that. int returnCode = _dbContext.Database.ExecuteSqlCommand("CheckReceivedNotificationDuplicate @p0, @p1, @p2", parameters: new[] { sendMessage.MESSAGE_TEMPLATE_NAME, sendMessage.MESSAGE_SUBJECT, sendMessage.MESSAGE_TEXT_SUMMARY }); Stored Procedure: ALTER PROCEDURE [dbo].

use parameter from method argument inside linq contains

若如初见. 提交于 2019-12-11 01:51:58
问题 i have a problem using Contains() method with parameter coming from the method arguments. i am using entity framework core 1.1 and mysql connector version 6.10.0-alpha. i have this code: public IEnumerable<Message> search(string content) { var bla = this.appDbContext.Messages.Where(x => x.Content.Contains("edit")).ToList(); var bla1 = this.appDbContext.Messages.Where(x => x.Content=="edit").ToList(); var bla2 = this.appDbContext.Messages.Where(x => x.Content==content).ToList(); var bla3 =

Db Resource Authorization in EF Core

泄露秘密 提交于 2019-12-11 01:25:29
问题 I'm writing a Rest API Framework, I'd like to create a db authorization context. The context takes in a role resolver and uses that to filter the default set. Base on a set of rules. In my First Attempt I thought maybe I could apply default filters to the entity sets to prohibit access to certain resources public class AuthorizationContext : DbContext { protected IConstraintResolver _constraintResolver; public AuthorizationContext(IConstraintResolver constraintResolver) { this.

How to scaffold EF core to existing DB?

非 Y 不嫁゛ 提交于 2019-12-11 00:59:30
问题 I am trying to reverse engineer an existing database using Entity Framework Core . I tried to follow the directions from Microsoft but I am presented with the error: Unable to find provider assembly with name EntityFramework. Ensure the specified name is correct and is referenced by the project. I am running the following command from the project directory: dnx ef dbcontext scaffold "Server=REMOVED;Database=REMOVED;User ID=REMOVED;Password=REMOVED" EntityFramework What am I doing wrong? 回答1:

The INSERT statement conflicted with the FOREIGN KEY constraint in Entity Framework Core

∥☆過路亽.° 提交于 2019-12-11 00:50:31
问题 I'm using Entity Framework 7 RC1, I have these entities: public class Book { [Key] public string BookId { get; set; } public List<BookPage> Pages { get; set; } public Author Author { get; set; } public string Text { get; set; } } public class BookPage { [Key] public string BookPageId { get; set; } public int Number { get; set; } } public class Author { [Key] public string AuthorId { get; set; } public string FullName { get; set; } } ApplicationDbContext.cs is default, with public DbSet<Book>

EntityFramework Core 2.0 skip loading column

元气小坏坏 提交于 2019-12-11 00:45:40
问题 I'm having some files saved into a MSSQL database using EF core with a structure like public class UploadedFile { public int Id { get; set; } public string Source { get; set; } public byte[] Content { get; set; } I want to be able to load the list of "UploadedFiles" from database without actually reading the Content column from the database. So I can't really use await _context.UploadedFiles.ToListAsync(); I believe I can use something like bellow with a stored procedure. _context.Set

dotnet ef command no longer works after upgrading to Visual Studio 16.3.0

折月煮酒 提交于 2019-12-11 00:39:39
问题 This happened at home first, so I thought maybe it was an issue with my desktop PC at home. But now that I am back at work, I tried the upgrade and got the same thing. Screenshot before upgrade Screenshot after upgrading Visual Studio The error I get is: Could not execute because the specified command or file was not found. Possible reasons for this include: You misspelled a built-in dotnet command. You intended to execute a .NET Core program, but dotnet-ef does not exist. You intended to run

Is it possible to hide the collection, which defines the relationship?

白昼怎懂夜的黑 提交于 2019-12-11 00:18:27
问题 When defining a many to many relationship EF Core mandates the use of a join class. I am trying to hide this join class. In my scenario a Person (entity 1) plays many Sports (entity 2), so there is a PersonSport (entity 3) table. Using Entity Framework Core I can do something like this: modelBuilder.Entity<Person>() .ToTable("Person") .Property(p => p.Surname) .HasField("_surname"); The class looks something like this: private readonly string _surname; public string Surname { get { return