entity-framework-core

VS Solution Explorer Analyzers exclamation: ef1000 “possible sql injection vulnerability”

ぐ巨炮叔叔 提交于 2020-01-21 06:31:00
问题 Strange message in Solution Explorer. ef1000 "possible sql injection vulnerability" It doesn't prevent compile, no errors, no warnings, no messages in "Errors List". No similar messages in the output on compile... Click doesn't move focus to "vulnerability" line. No referenced file/line related information. But there is context menu with "Delete" button which doesn't work (nothing happens). There are no Analyzers related entries in proj file. Looks like common package references bug. How to

Controller scaffolding doesn't work in VS 2017 preview for ASP.NET Core 2 Preview

感情迁移 提交于 2020-01-17 14:47:52
问题 I'm trying to use scaffolding to generate MVC Controller with views, using Entity Framework: I created ApplicationDBContext: public class ApplicationDbContext : DbContext { public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { } public DbSet<med1.Models.House> House { get; set; } } and added to ConfigureServices: services.AddDbContext<Data.ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); And

Returned object has null/empty ICollection unless it is accessed/inspected first

≯℡__Kan透↙ 提交于 2020-01-17 02:37:11
问题 Seeding deserialised JSON data in the Context and then attempting to return the DbSet. api/module returns all Modules with empty ICollections (null if I don't instantiate them), where as the Assessments happily return the virtual Module. Previous experience in MVC whereby I would have been accessing the object before it being sent to the view, so I haven't encountered this issue before. The commented out line: //Enumerable.ToList(ModuleItems.Include(mi => mi.Assessments)); Resolves the issue

There is no implicit reference conversion from ApplicationDbContext to Microsoft.EntityFrameworkCore.DbContext

淺唱寂寞╮ 提交于 2020-01-16 18:05:26
问题 While following the tutorial, I am getting an error when DbContextOptions<ApplicationDbContext> which is ApplicationDbContext inherit to IdentityDbContext but when I tried to inherit DbContext it works fine. Error Screen Shot: Exception message: The type 'WebExtractorPortalCore.Context.ApplicationDbContext' cannot be used as type parameter 'TContext' in the generic type or method 'DbContextOptions'. There is no implicit reference conversion from 'WebExtractorPortalCore.Context

What is the equivalent of the -IgnoreChanges switch for entity-framework core in CLI?

て烟熏妆下的殇ゞ 提交于 2020-01-16 05:52:05
问题 With Visual Studio one can run the command Add-Migration InitialCreate -IgnoreChanges in the Package Manage Console when creating the first migration of the model of an existing database with Code First workflow. What is the equivalent for CLI? The add command would be like this: dotnet ef migrations add InitialCreate but what about the ignore switch? 回答1: In the absence of any other way, one can empty the Up and Down method blocks of the migration of all code and run database update. public

Asp.Net core dbcontext issue

不打扰是莪最后的温柔 提交于 2020-01-15 11:07:00
问题 I am creating Asp.net core application and trying to connect to the database. I am getting an error at the following line of code in ConfigureServices method in the startup.cs file. The error that I am getting is the value cannot be null. It seems like it cant find the CustomerOrderEntities key in the web.config file. Not sure what the problem is services.AddDbContext<CustomerOrderEntities>(options => options.UseSqlServer(Configuration.GetConnectionString("CustomerOrderEntities"))); Startup

Web Api returns only one child object from one to many relationship using Entity Framework

独自空忆成欢 提交于 2020-01-15 09:12:57
问题 I've got a controller method that must return parent object with collection of children. In debug I can see plenty of children during execution but when I catch a json it has only one child. [Route("api/page/{id}")] public JsonResult GetPage(int id) { var item = db.Pages.Include(p => p.PageContainerTemplates) .SingleOrDefault(p => p.Id == id); return Json(item); } I've got many children and Entity Framework Core get them all but response json looks like this: { "name": "Index", "bodyClasses":

Web Api returns only one child object from one to many relationship using Entity Framework

北城余情 提交于 2020-01-15 09:10:31
问题 I've got a controller method that must return parent object with collection of children. In debug I can see plenty of children during execution but when I catch a json it has only one child. [Route("api/page/{id}")] public JsonResult GetPage(int id) { var item = db.Pages.Include(p => p.PageContainerTemplates) .SingleOrDefault(p => p.Id == id); return Json(item); } I've got many children and Entity Framework Core get them all but response json looks like this: { "name": "Index", "bodyClasses":

Nested Expression method call in Linq.Select()

喜欢而已 提交于 2020-01-15 08:20:25
问题 I use .Select(i=> new T{...}) after every db hit manually to convert my entity objects into DTO object. Here are some sample entities and DTOS User Entity; public partial class User { public int Id { get; set; } public string Username { get; set; } public virtual UserEx UserEx { get; set; } } User DTO; public class UserDTO { public int Id { get; set; } public string Username { get; set; } } UserEx entity; public class UserEx { public int UserId { get; set; } public string MyProperty1 { get;

Nested Expression method call in Linq.Select()

好久不见. 提交于 2020-01-15 08:19:28
问题 I use .Select(i=> new T{...}) after every db hit manually to convert my entity objects into DTO object. Here are some sample entities and DTOS User Entity; public partial class User { public int Id { get; set; } public string Username { get; set; } public virtual UserEx UserEx { get; set; } } User DTO; public class UserDTO { public int Id { get; set; } public string Username { get; set; } } UserEx entity; public class UserEx { public int UserId { get; set; } public string MyProperty1 { get;