entity-framework

Map a navigation property to a instance var as Foreign key

夙愿已清 提交于 2020-02-02 12:30:10
问题 I'm developing an Entity Framework Code First (v. 4.4.0.0) C# library with .Net Framework 4.0. I don't know how to set zero-to-one relationship. My model is the following: A Talk can be created by only one user ( StarterUserId ). A Talk can have only one recipient user ( RecepientUserId ) or only one group ( RecipientGroupId ). Note : That means that RecepientUserId is null if RecipientGroupId is not null; or RecepientUserId is not null if RecipientGroupId is null. A user can be a recipient

Why is Entity Framework generating a JOIN on SELECT

放肆的年华 提交于 2020-02-02 06:26:46
问题 I am using Entity Framework in a C# application and I am using Lazy Loading. We noticed one query has an extremely high impact on our CPU, which merely calculates a sum. When debugging the query generated by Entity Framework it creates a INNER JOIN (SELECT ... which is not performant. When I manually change the query to a proper JOIN the query time goes from 1.3 sec to 0.03 sec. Let me illustrate it with a simplified version of my code. public decimal GetPortfolioValue(Guid portfolioId) { var

String matching problem in Entity framework. Works for a string literal but not for a string variable

折月煮酒 提交于 2020-02-02 03:14:30
问题 I am trying to get a row from a table using the entity framework in C#. I have a table called "TipoPlanta" with a primary key called "Tipo" which is of type String. When I try to get a row from the table usng a String I can only find something if I use a string literal. If I use the string passed to the method I find no rows. I have the following method which has a bit of added stuff that I have been trying to debug. I pass the String tipoString which in this example has a value of "Arbol

String matching problem in Entity framework. Works for a string literal but not for a string variable

佐手、 提交于 2020-02-02 03:14:27
问题 I am trying to get a row from a table using the entity framework in C#. I have a table called "TipoPlanta" with a primary key called "Tipo" which is of type String. When I try to get a row from the table usng a String I can only find something if I use a string literal. If I use the string passed to the method I find no rows. I have the following method which has a bit of added stuff that I have been trying to debug. I pass the String tipoString which in this example has a value of "Arbol

Are there Database Initializers in Entity Framework Core?

对着背影说爱祢 提交于 2020-02-02 00:30:32
问题 I can't find examples on how to use EF Database Initializers with EF Core nor can I find a list of EF Database Initializers shipping with EF Core. Has the concept of Database Initializers become obsolete? What's the current approach of initializing a database ... or not initializing an existing database? 回答1: In .Net core you can use functions of Database property form DbContext instance. It allows you to create database (EnsureCreated), destroy database (EnsureDeleted) and migrate to last

Entity Framework 6 Code First migrations - multiple branches for production

一笑奈何 提交于 2020-02-01 15:32:33
问题 In my project we have a branch model that has a separate development branch and has a separate branch for each release. It may look like this: dev ______ ______ / \ / \ master --+---+----+---+---+----+----+--- (...) r1 \______/ r2 \_______/ So we develop on dev merge it to master and then we create a release branch (r1, r2, ...). We want to use EF 6 (manual not automatic) migrations but we have a question that we don't know how to answer. Imagine this: dev _(1)__ ____(4) / \ / \ master --+---

Entity Framework 6 Code First migrations - multiple branches for production

蹲街弑〆低调 提交于 2020-02-01 15:31:06
问题 In my project we have a branch model that has a separate development branch and has a separate branch for each release. It may look like this: dev ______ ______ / \ / \ master --+---+----+---+---+----+----+--- (...) r1 \______/ r2 \_______/ So we develop on dev merge it to master and then we create a release branch (r1, r2, ...). We want to use EF 6 (manual not automatic) migrations but we have a question that we don't know how to answer. Imagine this: dev _(1)__ ____(4) / \ / \ master --+---

EF6 Type of context 'System.Data.Entity.Core.Objects.ObjectContext' is not supported

最后都变了- 提交于 2020-02-01 04:22:44
问题 I have a new project created using Visual Studio 2013 with an ADO.NET Entity Data Model (EF6). Now I have to use some Dynamic Data function (like access to MetaTable object), so I add this code: MetaModel model = new MetaModel(); model.RegisterContext(() => { return ((System.Data.Entity.Infrastructure.IObjectContextAdapter)new KiwiJuiceEntities()).ObjectContext; }, new ContextConfiguration() { ScaffoldAllTables = true }); but I've got this error: Type of context 'System.Data.Entity.Core

EF6 Type of context 'System.Data.Entity.Core.Objects.ObjectContext' is not supported

牧云@^-^@ 提交于 2020-02-01 04:22:13
问题 I have a new project created using Visual Studio 2013 with an ADO.NET Entity Data Model (EF6). Now I have to use some Dynamic Data function (like access to MetaTable object), so I add this code: MetaModel model = new MetaModel(); model.RegisterContext(() => { return ((System.Data.Entity.Infrastructure.IObjectContextAdapter)new KiwiJuiceEntities()).ObjectContext; }, new ContextConfiguration() { ScaffoldAllTables = true }); but I've got this error: Type of context 'System.Data.Entity.Core

How to share a connection string between multiple entity data model

删除回忆录丶 提交于 2020-02-01 04:17:05
问题 I have a project that has 4 entity data model.for building them I don't want save a connection string in my project and I want store a connection string in app.config files and share it between my models.How I can do this? thanks 回答1: Assuming DbContext and model/database first. Leave the generated EF connection strings in your app.config file intact. As Arthur said, they contain the paths to the EF metadata (csdl/ssdl/msl). They are also used during development by the model designer. Add a