entity-framework-6.1

How can I change the default max length of string properties in Entity Framework 6?

旧巷老猫 提交于 2019-12-04 17:14:45
By default convention, strings properties in an entity model that are not explicitly given a max length are set to nvarchar(max) in the database. We wish to override this convention and give strings a max length of nvarchar(100) if they are not already explicitly set otherwise. I discovered the PropertyMaxLengthConvention built-in convention, which by its description and documentation would seem to be what I am looking for. However, it either doesn't work or I'm using it wrong or it just doesn't do what I think it does. I've tried simply adding the convention: modelBuilder.Conventions.Add(new

Entity Framework 6.1.1 Naming Convention for indexes

谁说胖子不能爱 提交于 2019-12-04 10:53:19
I understand how to add conventions to the code first (with migrations) project. I have successfully managed to perform the table names and even changed GUID Id fields to non-clustered. But I have not found how to change the default index name that EF supplies when no name is given. [Index(IsUnique = true)] public string Code { get; set; } [Index] public string Description { get; set; } I have these two requirements. The top index should be named UX_[schema]_[table]_Code , the second IX_[schema]_[table]_Description I also have the need to support multiple column indexes where IsUnique will

EntityFramework Stored Proc Function Import is it possible to read async?

不羁岁月 提交于 2019-12-04 04:57:29
I'm using EF 6.1.1 and Database First. When I import a stored proc into the edmx and generate the DBContext it looks like this: return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<TestSP_Result>("TestSP", params[]...) That returns an ObjectResult< T >, which implements IDbAsyncEnumerable< T > so I'm doing this to read the data async: IDbAsyncEnumerable<T> enumerable = objectResult as IDbAsyncEnumerable<T>; IDbAsyncEnumerator<T> enumerator = enumerable.GetAsyncEnumerator(); List<T> list = new List<T>(); bool moreItems = await enumerator.MoveNextAsync(CancellationToken.None);

Adding Inner Join to DbScanExpression in Entity Framework Interceptor

删除回忆录丶 提交于 2019-12-03 17:13:49
问题 I'm trying to use an Entity Framework CommandTree interceptor to add a filter to every query via a DbContext. For the sake of simplicity, I have two tables, one called "User" with two columns ("UserId" and "EmailAddress") and another called "TenantUser" with two columns ("UserId" and "TenantId"). Each time there is a DbScan of the User table, I want to do an inner join against the TenantUser table and filter based on the TenantId column. There is a project called EntityFramework.Filters that

entity framework code first migration keep existing data

南笙酒味 提交于 2019-12-03 12:03:10
问题 I am using EF 6.1 and I use code first approach with an existing database with data in a production environment. Is it possible at all to migrate model changes and keep the existing customer`s data? 回答1: Yes, however, it can be complicated depending on specific case (on complexity of changes): Overview: https://docs.microsoft.com/en-us/ef/ef6/modeling/code-first/migrations/existing-database Read this: https://docs.microsoft.com/en-us/ef/ef6/modeling/code-first/migrations/index And then this:

How to totally lock a row in Entity Framework

风格不统一 提交于 2019-12-03 11:18:04
I am working with a situation where we are dealing with money transactions. For example, I have a table of users wallets, with their balance in that row. UserId; Wallet Id; Balance Now in our website and web services, every time a certain transaction happens, we need to: check that there is enough funds available to perform that transaction: deduct the costs of the transaction from the balance. How and what is the correct way to go about locking that row / entity for the entire duration of my transaction? From what I have read there are some solutions where EF marks an entity and then compares

Code first Entity Framework 6.1 Custom Aggregate Function

我怕爱的太早我们不能终老 提交于 2019-12-03 08:46:31
I have a custom CLR Aggregate function on SQL Server to calculate percentiles. Is it possible to call my custom aggregate function through Entity Framework? How is the mapping configured to allow this? I have tried using codefirstfunctions similar to what is described on Entity Framework 6 Code First Custom Functions , however the functions seem to only be allowed to take scaler parameters, where my function is an aggregate function so will need to take a list of items (similar to how Sum, Averagg and Count work). The Aggregate functions has the following signature, taking in the value we want

entity framework code first migration keep existing data

五迷三道 提交于 2019-12-03 03:32:34
I am using EF 6.1 and I use code first approach with an existing database with data in a production environment. Is it possible at all to migrate model changes and keep the existing customer`s data? Yes, however, it can be complicated depending on specific case (on complexity of changes): Overview: http://msdn.microsoft.com/en-us/library/dn579398.aspx#option1 Read this: http://msdn.microsoft.com/en-us/library/jj591621.aspx And then this: http://msdn.microsoft.com/en-us/library/dn481501.aspx 来源: https://stackoverflow.com/questions/23415921/entity-framework-code-first-migration-keep-existing

How can you add a navigation property on a view in EF 6.1 CodeFirst

一笑奈何 提交于 2019-12-01 22:16:08
问题 Let's make a case to explain my problem. MyTable1 +id +myTable2Id MyTable2 +id MyView1 +id +myTable2Id MyView1 exists in the case, from data from the MyTable1. Now i want to create a Navigation property from my EF6.1 Code first approach in my View to MyTable2. I know that it was possible from the database first approach, but is it also possible from the code-first approach and how? EDIT: I search some on internet, but due many meanings of the word View, it's very hard to find information on

How can you add a navigation property on a view in EF 6.1 CodeFirst

こ雲淡風輕ζ 提交于 2019-12-01 18:45:09
Let's make a case to explain my problem. MyTable1 +id +myTable2Id MyTable2 +id MyView1 +id +myTable2Id MyView1 exists in the case, from data from the MyTable1. Now i want to create a Navigation property from my EF6.1 Code first approach in my View to MyTable2. I know that it was possible from the database first approach, but is it also possible from the code-first approach and how? EDIT: I search some on internet, but due many meanings of the word View, it's very hard to find information on it. Also with the approaches in codes that i tried, i always get an error that the migration can't be