entity-framework

Same EDMX file for different Providers

倖福魔咒の 提交于 2020-01-23 08:36:51
问题 I'm working on a project where I have a local database (SQL CE) which is used as sort of a buffer while no connection to the server exists. On the server I want to use the same database-layout. Of course I want to use the same EDMX-File which is in a Common.dll available on the Server and the Client. In the Client I have a connection string with provider=System.Data.SqlServerCe.3.5 while it is provider=System.Data.SqlClient on the server. My problem comes when I want to save sth on the Server

Sort by New Guid for random order

送分小仙女□ 提交于 2020-01-23 08:04:21
问题 In order to get results in a random order from a Sql query I generally sort by new Guids. I have done this before with Entity-Framework, however for some reason its not working now. For example (using the adventureworks2008r2 database) i run the following query in LinqPad: (from t in Employees orderby Guid.NewGuid() select new {t.Person.FirstName,t.Person.LastName,t.JobTitle}) This generates the following SQL: SELECT [t1].[FirstName], [t1].[LastName], [t0].[JobTitle] FROM [HumanResources].

NullReferenceException in EF 5-6.1.1 with two navigation properties to the same type

眉间皱痕 提交于 2020-01-23 07:53:27
问题 I'd like to start with that I have a workaround for this issue - but I spent a few hours today figuring out the cause of the exception, so I'd thought I'd share Given two entities in the domain: public class User { public int Id { get; set; } public string Name { get; set; } } public class Ticket { public int Id { get; set; } public string Name { get; set; } public virtual User Owner { get; set; } public int? LockedByUserId { get; set; } public virtual User LockedByUser { get; set; }

Why the database data is not being updated but object did and without error?

﹥>﹥吖頭↗ 提交于 2020-01-23 06:52:00
问题 I have this bank ATM mock-up app which implements some Domain-Driven Design architecture and Unit of Work pattern. This app have 3 basic functions: Check balance Deposit Withdraw These are the project layers: ATM.Model (Domain model entity layer) namespace ATM.Model { public class BankAccount { public int Id { get; set; } public string AccountName { get; set; } public decimal Balance { get; set; } public decimal CheckBalance() { return Balance; } public void Deposit(int amount) { // Domain

Why the database data is not being updated but object did and without error?

风格不统一 提交于 2020-01-23 06:51:28
问题 I have this bank ATM mock-up app which implements some Domain-Driven Design architecture and Unit of Work pattern. This app have 3 basic functions: Check balance Deposit Withdraw These are the project layers: ATM.Model (Domain model entity layer) namespace ATM.Model { public class BankAccount { public int Id { get; set; } public string AccountName { get; set; } public decimal Balance { get; set; } public decimal CheckBalance() { return Balance; } public void Deposit(int amount) { // Domain

Creating Interface for ObjectContext

為{幸葍}努か 提交于 2020-01-23 06:20:09
问题 I'm trying to create an abstracted layer for ObjectContext . I understand OC is a Unit of Work, but I'm just not entirely how to write a good interface for it. Ideally I'd like to be able to swap out my 'RealDataContext' that implements IDataContext for something like a 'FakeDataContext' that would be fully in-memory. The reason for this is that I want to be able to test my repositories against an in-memory database. Thanks! 回答1: You should be able to create an extended class that derives

EF Code First Not Generating Tables

被刻印的时光 ゝ 提交于 2020-01-23 05:38:05
问题 I'm working on an EF Code first site, and I've written my classes and a context class, the source of which is: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.Entity; using MySite.SalesTool.Data.Entities; using System.Data.Entity.ModelConfiguration.Conventions; namespace MySite.SalesTool.Data { public class SalesToolEntities : DbContext { public DbSet<User> Users { get; set; } public DbSet<UserRole> UserRoles { get; set; } public DbSet

OptimisticConcurrencyException — SQL 2008 R2 Instead of Insert Trigger with Entity Framework

半腔热情 提交于 2020-01-23 05:30:07
问题 Using a SQL 2008 R2 November release database and a .net 4.0 Beta 2 Azure worker role application. The worker role collects data and inserts it into a single SQL table with one identity column. Because there will likely be multiple instances of this worker role running, I created an Insert Instead Of trigger on the SQL table. The trigger performs Upsert functionality using the SQL Merge function. Using T-SQL I was able to verify the insert instead of trigger functions correctly, new rows were

Invalid Column name when using savechanges() in entity framework

感情迁移 提交于 2020-01-23 04:40:13
问题 So here is the deal, I have changed my database schema, and changed the PK for one of my tables and I have removed everything related to the old PK (FK reference in another tables). However I have this exception when I insert a new entity using savechanges() method ex = {"An error occurred while updating the entries. See the inner exception for details."} And the inner exception is InnerException = {"Invalid column name 'Audit_ID'."} the Audit_ID is the old PK. I have tried this "Invalid

EF Code First binding to listbox

我只是一个虾纸丫 提交于 2020-01-23 03:22:28
问题 I would appreciate it if somebody could tell me how to bind a listbox to the entity framework (EF code first). I'm using prism and mef. There are two views, one with a button and another with a listbox. (each in their own prism region). By clicking the button I create a new Employee object and insert it to the database via the entity framework. The problem is that my listbox doesn't show me the newly added Employee object in the list. What should be changed to make this work? Some parts of