entity-framework-6

How to force fire OnModelCreating every DataContext initialized up

好久不见. 提交于 2020-01-11 07:01:08
问题 I want to fire OnModelCreating every new DataContext(new Entity()) ... But when i create a connection of a table , it works. When create a connection for another table, OnModelCreating doesnt work again, so because i got error, the entity type <tableName> is not part of the model for the current context. public class DataContext : DbContext { private BaseEntity _entity; public DataContext(BaseEntity entity) { Database.Connection.ConnectionString = Parameters.ConnectionString; _entity = entity

Entity Framework complex type's columns naming convention

十年热恋 提交于 2020-01-11 06:00:12
问题 Using complex types the default column naming convention uses underscore. That means having type defined that way: [ColmplexType] public class Contact { string Email {get;set;} string Post {get;set;} } public EntityN { //... public Contact Contact {get;set;} } we will get columns named such way Contact_Email nvarchar(max) Contact_Post nvarchar(max) We of course could configure each column name separately using ColumnAttribute or Context.Properties mapping, but do we have a possibility to

EF6 alpha Async Await on an Entity Stored Procedure / Function Import?

五迷三道 提交于 2020-01-11 05:38:09
问题 I'd like to apply the new async await functionality to Stored Procedures / Function Imports imported in my Entity model, but have as yet been unable to with the EF6 alpha. Is it yet possible in EF6 alpha2 (or the nightly build as of 20211) to call any of the new Async methods on an Entity Function Import (which calls a SQL Stored Procedure) that returns a collection of Complex Type? e.g. private async Task<IList<Company>> getInfo (string id) { using (CustomEntity context = new CustomEntity())

Entity Framework 6: is there a way to iterate through a table without holding each row in memory

牧云@^-^@ 提交于 2020-01-11 02:06:46
问题 I would like to be able to iterate through every row in an entity table without holding every row in memory. This is a read only operation and every row can be discarded after being processed. If there is a way to discard the row after processing that would be fine. I know that this can be achieved using a DataReader (which is outside the scope of EF), but can it be achieved within EF? Or is there a way to obtain a DataReader from within EF without directly using SQL? More detailed example:

DbUpdateConcurrencyException using Entity Framework 6 with MySql

*爱你&永不变心* 提交于 2020-01-10 05:33:05
问题 I'm having trouble with concurrency checks using EF6 and MySQL. The problem I'm having is that I get a concurrency exception thrown when I try to save data to the database. If you examine the sql that is output to the console it tries to query the concurrency field from the database using the old value in the where clause. Because this field has been updated by the database. Environment: Windows 7 64 bit Visual Studio 2013 Nuget packages installed: EF 6.0.1 MySql.ConnectorNET.Data 6.8.3.2

Trouble with building a C# EntityFramework IQueryable Expression

▼魔方 西西 提交于 2020-01-09 11:45:21
问题 So I'm attempting to build a semi complication Search expression, but I'm stuck trying to create a basic one. The expressions being used for getValueExpression look something like: x => x.PropertyA != null ? x.PropertyA.ToShortDateString() : "" //nullable datetime x => x.PropertyB //string property x => x.PropertyC != null x.PropertyC.ToString() : "" //nullable int Here is my function code, it currently errors when getValueExpression being of type Func that can't be compared to a string,

Trouble with building a C# EntityFramework IQueryable Expression

走远了吗. 提交于 2020-01-09 11:44:58
问题 So I'm attempting to build a semi complication Search expression, but I'm stuck trying to create a basic one. The expressions being used for getValueExpression look something like: x => x.PropertyA != null ? x.PropertyA.ToShortDateString() : "" //nullable datetime x => x.PropertyB //string property x => x.PropertyC != null x.PropertyC.ToString() : "" //nullable int Here is my function code, it currently errors when getValueExpression being of type Func that can't be compared to a string,

Configure multiple database Entity Framework 6

删除回忆录丶 提交于 2020-01-09 04:38:49
问题 In my solution I have 2 projects that use Entity Framework 6. Each points to a different database, both using the same data provide - SQL Server. A third project in my solution needs to use both databases. My problem is how to configure those context. I tried to create a configuration class in a separate assembly: namespace OSAD_Base { class EfDbConfiguration : DbConfiguration { public EfDbConfiguration() { SetProviderServices(SqlProviderServices.ProviderInvariantName, SqlProviderServices

how to check for entities/relationships generically

僤鯓⒐⒋嵵緔 提交于 2020-01-07 14:38:12
问题 I have entities/relationships like following A -> B; B -> C, B -> D, B -> E, ... When a user wants to delete entity A, I check whether any of its children B entities have any records for C entities, and D entities, etc and provide a detailed error message. However, the requirement is that we might end up adding more entity types such as B -> FutureEntity. Is there a way to either generically check for all of these, or atleast make sure that in the future if such an entity gets added, I modify

Entity Framework (EF6) + MySql Database First Model Many to Many Relationship Wrong Query Generation

巧了我就是萌 提交于 2020-01-06 20:02:42
问题 I have a project which has an existing database structure and data. Currently project is running on PHP + MySQL and I'm trying to switch from PHP to C# EF 6.0 + MySQL Database first approach. I have installed NuGet Packages (EF 6.0 and MySQL.Data, MySQL.Web, MySQL.Data.Entity, MySQL.Data.Entities) and modified my app.config according to use MySQL data provider. Up to this state everything works perfectly, I can generate model from database and can insert data on each table without any issue