entity-framework-6

EF in WinForms: how to filter data in BindingSource/DGW (.Local.ToBindingList())

时间秒杀一切 提交于 2020-01-02 08:56:09
问题 I generated an EF model (Database first) and DataSource following this tutorial http://msdn.microsoft.com/en-us/data/jj682076.aspx On my form I created BindingSource (bsUsers) and bound DataGridView to it. Here is how I load data on form startup: _myDbContext = new MyDbContext(); _myDbContext.Users.Load(); bsUsers.DataSource = _myDbContext.Users.Local.ToBindingList(); It works, I can add and modify records using DataGridView and other bound controls. But the thing I didn't figure out is how

EF Database first how to update model for database changes?

对着背影说爱祢 提交于 2020-01-02 07:17:08
问题 In a class library Ado.net Entity Data Model is has generated POCO classes. These were generated fine for the first time. But database changes are not being reflected. In edmx diagram right clicking and choosing Update Model from Database show newly created table but it do not add table even after selecting it to add. I tried running .tt (by right click and Run custom tool) but even it did not regenerated the Poco classes as per latest DB changes. Help please 回答1: Not a fix but a workaround:

How to add new entity properties in Entity Framework without changing database model

本小妞迷上赌 提交于 2020-01-02 05:32:08
问题 I am new to Entity Framework. I started with database first approach which created my classes corresponding to the tables I selected. I am using MVC . One of my tables has a Date column in it. My requirement is I want to display the Day in my gridview (Grid MVC) i.e. if Date for that particular record fetched is 10/27/2015, then Day should show Tues. I want to do this without adding an extra column for the day in my database. Is there a way for this. Any help will be greatly appreciated. My

Extract strongly-typed data context instance from arbitrary query

我只是一个虾纸丫 提交于 2020-01-02 02:25:27
问题 Background We have a class library which has a grid (inherits from WPF DataGrid) with refresh functionality. The grid has a IQueryable Query property, which enables the refresh. Each grid's query is defined not in the class library, but in the referencing end-project: var dg = new RefreshableDataGrid(); dg.Query = () => new ProjectDbContext().Persons; Each grid also has a textbox for text filtering. When text is entered in the filter, an expression is generated which checks if any string

Can I use Entity Framework 6 with Visual Studio 2010?

隐身守侯 提交于 2020-01-02 00:57:15
问题 Our development team (and build servers) successfully use a mixture of Visual Studio 2010 and Visual Studio 2012 for our application. However, since upgrading from EF5 to EF6, we no longer seem to be able to build with VS2010. Specifically, the build machines won't build at all. VS2010 on my desktop does seem to build, but I get the following errors: Error 4 Error 10023: Could not find the conceptual model to validate. Error 5 Error 10024: Could not find the storage model to validate. Error 6

Entity framework update one column by increasing the current value by one without select

假如想象 提交于 2020-01-01 09:13:17
问题 What I want to achieve is the simple sql query: UPDATE TABLE SET COLUMN = COLUMN + 1 Is there a way to make it happen without loading all records (thousands) to memory first and loop through each record to increment the column and then save it back? EDIT I tried raw sql and it worked. I have to decide the sql provider from the connection string and the database schema name from the connection context. After that, I will use the corresponding sql query to update the table. For SQL, it looks

DDD - Consistency of Entity Across Bounded Context & Different Schemas in Database

风流意气都作罢 提交于 2020-01-01 05:24:27
问题 I am implementing DDD with Entity Framework Code First. My Domain Model is persisted as it is without any mapping layer. I am following approach suggested during Tech-Ed by Julie Lerman. Each bounded context maps to different schema within same database. If same entity say, Customer appears across different bounded contexts how do we maintain consistency of data for Customer entity? 回答1: Only a single bounded context will be the system of record for your entity. If you cannot get away with

Create Foreign Key using Data Annotations

馋奶兔 提交于 2020-01-01 05:18:12
问题 In the code below, I need to set a foreign key constrant on ParentInfoAddProperties.ParentQuestionAnswersId so that it is dependent on ParentQuestionAnswers.Id (which is a Primary Key). I am attempting to do so using data annotations but Entity Framework 6 wants to create a new Foreign Key column in my ParentQuestionAnswers table which references the ParentInfoAddProperties.Id column not the ParentInfoAddProperties.ParentQuestionAnswersId column. I do not want Entity Framework to create a new

ASP.NET Identity - Error when changing User ID Primary Key default type from string to int AND when using custom table names

微笑、不失礼 提交于 2020-01-01 05:10:08
问题 I'm using Microsoft.AspNet.Identity 2.0.0-beta1 and Entity Framework 6.1.0-beta1 (released 11 Feb 2014). I'm getting the following error when I try to change the default type of User ID Primary Key from string to int AND when I try to use custom table names (so User.MyUsers instead of dbo.AspNetUsers): " The entity types 'IdentityUser' and 'ApplicationUser' cannot share table 'MyUsers' because they are not in the same type hierarchy or do not have a valid one to one foreign key relationship

Net Core 2 - Entity Framework: Update-Database of different environment

余生颓废 提交于 2020-01-01 03:36:10
问题 FACTS: net core 2.0 project entity framework (code first) different appsettings.json file for different environments I utilize Package Manager Console to generate my DB scripts (Add-Migration, Update-Database) If I run PM>"Get-DbContext" it brings back info pulled from my appsettings.Development.json file GREAT, that's what I want most of the time! But how do I tell it to pull db variables from appsettings.Staging.json instead of development for PM commands? I tried creating new