entity-framework

Entity Framework primary key constraint

风流意气都作罢 提交于 2021-01-29 18:42:28
问题 I am using Entity Framework 6.0 with Microsoft SQL Server. By default, the primary key it generates for a table is named like PK_dbo.TableName , where TableName is in a plural form, even though the actual name of the table is in a singular form. For example, I have a table named dbo.Employee . Yet the primary key denoted by EF 6 is PK_dbo.Employees . Is there any way to change the primary key to something like PK_TableName where the TableName is in a singular form? Update: Thanks for the

Is a DbSet required to run a stored procedure?

两盒软妹~` 提交于 2021-01-29 18:34:59
问题 I have a stored procedure that returns data from a multi-table query. To do this do I need to create a DbSet for each of the tables that are involved in the query? All the examples I find that use FromSql have a DbSet (e.g., Books in the below example) specified before the FromSql clause. using (var context = new SampleContext()) { var books = context.Books .FromSql("EXEC GetAllBooks") .ToList(); } My understanding is a DbSet represents an table. Note that I am working against an existing DB

Joining two tables in EF Core, invalid column name

流过昼夜 提交于 2021-01-29 17:59:46
问题 I am trying to join two tables in EntityFramework Core using linq syntax in the following way: var results = dc.EntityA.Join(dc.EntityB, a => a.StringProperty, b => b.StringProperty, (a, b) => DoSomeStuff(a, b)).ToList(); Where StringProperty is a string column in the database. I am getting the error {"Invalid column name 'EntityId'."} I found this similar question Entity Framework: Invalid column name 'OrganizationStructure_ID' where it is suggested to set the foreignkeys during

It is possible to use child class to implement Separation of concerns using EF Core?

假如想象 提交于 2021-01-29 16:44:56
问题 My goal is async loading of related entities using DBContext. Let imagine two projects. The first named MyApp.Domain and contains domain entities. namespace MyApp.Domain { public class PlanPage { public Guid Id { get; set; } } } namespace MyApp.Domain { public class PlanPageDay { public Guid Id { get; set; } public Guid PlanPageId { get; set; } } } The second project named MyApp.Infrastructure.EntityFramework and contains configuration of projection entities to database. It also contains

How to Create Migration on Runtime in Entity Framework Core

送分小仙女□ 提交于 2021-01-29 16:07:08
问题 Is there any possible way to create migration on runtime in efcore. context.Database.Migrate(); Before this code, I need a code that, when I started my app, should create a migration about diff between postgresql database tables and ef models. Is there any way to do this? PM> enable-migrations PM> add-migration initial PM> update-database I dont want to use these ones. I want to make these code's jobs on runtime. I hope I could explain myself clearly. 回答1: Note, you need to re-compile the app

C# MVC Model view connecting 2 different database columns

半世苍凉 提交于 2021-01-29 15:20:58
问题 This is the first time I have attempted to join information from one database to the other. I have a accounting database and a regular site database. Trying to keep them separate. I have a page that shows Transactions but am getting the information for a few of the columns from the regular database by way of Id's. Below is my Model. I am showing nothing in the fields for the items in the other database. public class Transaction { [Key] public Guid TransactionId { get; set; } public string

Issue with Entity Framework 6 while connecting to SQL Server from Azure function V2

血红的双手。 提交于 2021-01-29 14:33:21
问题 I am trying to use an existing library which is a .net library which uses EF 6.0 to connect to a database. Since Azure Functions does not have an app.config file, I am trying to set the connection string using C# code. But I am getting the following exception while connecting to the DB using my DB context: System.ArgumentException: The ADO.NET provider with invariant name 'System.Data.SqlClient' is either not registered in the machine or application config file, or could not be loaded. See

Read Oracle SYS_REFCURSOR in C# Entity Framework?

我们两清 提交于 2021-01-29 14:23:30
问题 I have a simple C# console application and its code is like this: using System; using System.Collections.Generic; using System.Data; using System.Data.Common; using System.Linq; using System.Text; using System.Threading.Tasks; using Oracle.ManagedDataAccess.Client; namespace ConsoleApp1 { class Program { static void Main(string[] args) { SHRSContext shrsContext = new SHRSContext(); DbCommand cmd = shrsContext.Database.Connection.CreateCommand(); cmd.CommandText = "PKG_SHRS.GETLOGINATTEMPT";

use multiple dbContext in one application

你。 提交于 2021-01-29 12:51:56
问题 I am struggling with using multiple dbContext with an single web application in ASP.NET MVC 5. I am following code First existing database design approach. i need guideline how to do that say in example if i am creating 5 models using ADO.NET, it will create 5 dbContext along with its model classes. how it will change in web.config file? Many Thanks public partial class DefaultContext : DbContext { public DefaultContext() : base("name=DefaultContext") { } protected override void

Entity Framework primary key constraint

左心房为你撑大大i 提交于 2021-01-29 12:44:45
问题 I am using Entity Framework 6.0 with Microsoft SQL Server. By default, the primary key it generates for a table is named like PK_dbo.TableName , where TableName is in a plural form, even though the actual name of the table is in a singular form. For example, I have a table named dbo.Employee . Yet the primary key denoted by EF 6 is PK_dbo.Employees . Is there any way to change the primary key to something like PK_TableName where the TableName is in a singular form? Update: Thanks for the