entity-framework-core

Protect SQLite database used by EntityFramework Core Application

↘锁芯ラ 提交于 2019-12-05 10:20:54
I'm trying to use EntityFramework Core 1.0 (new name for EntityFramework 7) to manage an SQLite database in a C# Desktop application. I read official documentation and my test-application works. My question is: is it possibile to password-protect the database? I know that there are lot of way to do it, it exists also the .NET class System.Data.SQLite that allow to do that, but how to do it using EFCore 1? I can't understand if it is possible. Thanks for help, Enrico With EntityFramework Core 2.0 (EFCore 2.0), It is possible to use Encrypted SQLite database. Steps for using SQLite Encrypted

Scaffold-DbContext creating model for table without a primary key

半腔热情 提交于 2019-12-05 10:04:24
问题 I am trying to create DBcontext and corresponding model for a particular table in ASP.NET core MVC application. This table doesn't have any primary key. I am running following Scaffold-DbContext command- Scaffold-DbContext "Server=XXXXX;Database=XXXXXXX;User Id=XXXXXXX;password=XXXXXXX" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -t TABLE_NAME -force -verbose In Package Manager Console, I can see this verbose output- ............... ............... Unable to identify the primary

EF Core fluent mapping to inner object properties

丶灬走出姿态 提交于 2019-12-05 09:55:48
I have a class that contains some properties. For some architectural reasons, I have an instance of another objet into my class. Simple example public class MyEntity { public MySubEntity SubEntity {get; set;} } For this, I create fluent mapping like : builder.ToTable(MyEntity.CONST_TABLE_NAME); builder.HasKey(m => m.Id); builder.Property(m => m.Column1).IsRequired(); builder.Property(m => m.SubEntity.Column2).IsRequired(); I cannot integrate all my subEntity properties into my main entity (my subEntity has its own intelligence). I just want to map my subentity properties, which is NOT stored

Add-Migration Error in Entity Framework Core

送分小仙女□ 提交于 2019-12-05 08:52:58
I am following Julie Lerman's Getting Started with Entity Framework Core 2.0 tutorial. I have installed Microsoft.EntityFrameworkCore.SqlServer Version 2.0.2. When I try to run add-migration initial (Package Manager Console) in VS 2017 I am obtaining the below error : System.IO.FileLoadException: Could not load file or assembly 'Microsoft.EntityFrameworkCore.SqlServer, Version=2.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) File name: 'Microsoft.EntityFrameworkCore

.NET Core Entity Framework stored procedures

故事扮演 提交于 2019-12-05 08:39:46
I'm trying to port a ASP.NET 4.5 application to .NET Core and I have one real issue I can't seem to figure out. My existing application executes stored procs which return a dataset with multiple datatables. The Entity Framework can automatically map the returned fields to my entity properties but only works with the first datatable in the dataset (naturally). So I'm just trying to figure out if its at all possible to somehow intercept the model building process and use custom code to process the dataset and look into the other datatables to set entity fields. I know I can use the normal way of

Package 'Microsoft.EntityFrameworkCore.SqlServer' is incompatible with 'all' frameworks in the project

别来无恙 提交于 2019-12-05 08:38:51
I was trying to add the package named Microsoft.EntityFrameworkCore.SqlServer by running the command. dotnet add package Microsoft.EntityFrameworkCore.SqlServer in Visual Studio Code, but I get this error: Package Microsoft.EntityFrameworkCore.SqlServer 2.0.0 is not compatible with netcoreapp1.1 (.NETCoreApp,Version=v1.1). Package Microsoft.EntityFrameworkCore.SqlServer 2.0.0 supports: netstandard2.0" (.NETStandard,Version=v2.0). Package 'Microsoft.EntityFrameworkCore.SqlServer' is incompatible with 'all' frameworks in project 'C:\users\username..' I was using version 1.1. Try to run the below

EntityTypeBuilder does not contain a definition for ToTable in EF Core

耗尽温柔 提交于 2019-12-05 08:26:48
问题 I have this sample code: using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Models; namespace MySampleNamespace { public class MyDbContext : DbContext { public MyDbContext(DbContextOptions<MyDbContext> options) : base(options) { } public DbSet<User> Users { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { new UserMap(modelBuilder.Entity<User>()); } public class UserMap { public UserMap(EntityTypeBuilder<User>

EF Core with ASP MVC .NET 4.6

六月ゝ 毕业季﹏ 提交于 2019-12-05 08:12:34
In a project I need to set up an ASP.NET MVC (with .NET 4.6.1) but using the "new" EF Core for accessing the database. Unfortunately every documentation explains only how to setup an ASP.NET Core MVC project. I just gave it a try and when it comes to creating the database via the Package Manager Console I get the error message: No parameterless constructor was found on 'DataContext'. Either add a parameterless constructor to 'DataContext' or add an implementation of 'IDbContextFactory' in the same assembly as 'DataContext' Yes, I don't have a parameterless constructor but neither does the

Separate In Memory Databases EF7

ぐ巨炮叔叔 提交于 2019-12-05 07:15:40
Is there any way to create a separate (isolated) instance of an EF7 In Memory Database? I am using the In Memory Database in Entity Framework 7 in my unit tests written in xUnit. I would like to be able to run the tests in parallel but this isn't really possible since it seems like the same in memory database is used for all the tests. What I would like is for each test to have its on isolated in memory database that isn't shared with the other tests that run in parallel. In EF Core you can pass a db name for InMemory db context. Something like var builder = new DbContextOptionsBuilder();

How does EF7 bootstrap dependency injection (IServiceCollection) if you're not in ASP.NET 5?

我的未来我决定 提交于 2019-12-05 06:48:31
问题 I'm still trying to get my head around what's what with ASP.NET 5 / EF 7. I'm using DNX projects (.xproj). Startup is used by OWIN/ASP.NET for configuring, loading services, etc. But it's also used for EF 7 migrations (to set your DbContextOptions for example). My main goal is to know how EF7 (and ASP.NET 5) bootstrap with Startup and who's creating the startup class, initializing the DI container, etc. An example of what I need to do, for context, is that in my xUnit unit tests (which are in