entity-framework-4.1

WPF and entity Framework code first

北慕城南 提交于 2019-12-10 09:56:38
问题 I would like to implement a simple WPF with a datagrid and a save button. when I click save button it will accept changes (row edit,cell edit, new row, delete etc) I tried RowEditHandler and CollectionChange event using observable collections. But I couldnt get a soluton. Can anyone please show me a simple way. Using dataset (xsd), I was able to achive that simpy by sending datacontext of grid to dataset and using update function. thanks for help 回答1: The ADO.NET team blog has an example how

Can Entity Framework 4.1 designer “update model from database” for selected entities only?

一笑奈何 提交于 2019-12-10 04:19:26
问题 The situation: Sometimes a database schema is not what you would consider an ideal representation of the system's information and you may not be able to change it. We have been using Entity Framework to create a nicer conceptual model to code against in situations like this. This means updating the model from the database and then changing it ourselves, either through the designer or through the .edmx file directly using a text editor. The problem: When you update the model from the database,

Populating child property with Entity Framework SqlQuery

穿精又带淫゛_ 提交于 2019-12-10 01:48:09
问题 Given the following POCO Code First Entities public class Customer { public int CustomerId { get; set; } public string CustomerTitle { get; set; } public string CustomerFirstName { get; set; } public string CustomerLastName { get; set; } public ICollection<Order> Orders { get; set; } } public class Order { public int OrderId { get; set; } ... public int CustomerId { get; set; } public Customer Customer { get; set; } } Using linq you can get the Orders filled in by using the Include property

Entity with many-to-many relationship creation fails after upgrading to RC

最后都变了- 提交于 2019-12-09 20:57:03
问题 I've got a project with 3 simple tables, a couple of POCO classes, and a DBContext created with code, no edml file. The following code setup used to work with the beta of Entity Framework code-first, I've edited the DbContext code since the ModelBuilder changed from the beta to RC Tables (simple tables many-to-many table has fields declared as foreign keys with cascade deletion): CREATE TABLE [dbo].[Bookings]( [ID] [int] IDENTITY(1,1) NOT NULL, [StartDate] [datetime] NOT NULL, [EndDate]

DbContext throws exception on query when accessed through interface

我的未来我决定 提交于 2019-12-09 17:58:30
问题 I have created an interface that my DbContext class implements, this enables me to create a fake db context for unit testing. This works well for all my LINQ queries so far but one, where I get the following exception: Unable to create a constant value of type 'DemoApp.Member'. Only primitive types ('such as Int32, String, and Guid') are supported in this context. Executing the LINQ query through the interface throws the above exception, however when executing the exact same query directly on

How do I turn off change tracking at the DbContext level in EF 4.1 RC?

柔情痞子 提交于 2019-12-09 17:56:30
问题 I've encountered what seems to be a common problem: I am updating values in my database, but EF is using its original in-memory copy of the object and these changed values are not reflected in the displayed data. I understand why this is, but I can't figure out a way around it. The most common solution seems to be to set MergeOptions.NoTracking to turn off change tracking completely (or use the AsNoTracking() extension method when querying) and force a refresh every time the object is

Code-First Entity Framework inserting data with custom ID

岁酱吖の 提交于 2019-12-09 17:21:42
问题 I am using code-first EF in my project and face issue when the data with custom id is being inserted. When I am trying to insert data with custom ID (for instance 999), EF ignores it and inserts incremented ID into table. My model: public class Address { [Key] public int Id { get; set; } public string FirstName { get; set; } ... } How to solve this probleb? EDIT: 1) How to begin incrementing from N, but not from 0? 2) If I don't specify custom ID, DB must increment and inserts own. If I

Entity Framework 4.1 RC: Code First EntityTypeConfiguration inheritance issue

痴心易碎 提交于 2019-12-09 15:30:26
问题 I am trying to use a common EntityTypeConfiguration class to configure the primary key for all of my entities, so that each derived configuration class does not repeat itself. All of my entities implement a common interface IEntity (which says that each entity must have an Id property of type int). My configuration base class looks like this: public class EntityConfiguration<TEntity> : EntityTypeConfiguration<TEntity> where TEntity : class , IEntity { public EntityConfiguration() { HasKey( e

Entity Type Has No Key Defined

匆匆过客 提交于 2019-12-09 14:57:34
问题 Another 'Entity Type 'x' has no key defined' question, but I've set the [Key] attribute on a property so I'm a bit confused. Here's my entity and context classes: namespace DoctorDB.Models { public class Doctor { [Key] public string GMCNumber; [Required] public string givenName; [Required] public string familyName; public string MDUNumber; public DateTime MDUExpiry; public string MDUCover; } public class DoctorContext : DbContext { public DbSet<Doctor> Doctors { get; set; } } } When I go to

Entity Framework and sharded database

元气小坏坏 提交于 2019-12-09 12:59:53
问题 I have a WCF Data Service running on top of a Entity Framework code first 4.1 provider. The database is quite large (one key table has 77+ million records and grows by ~10% per month) and has presented quite a performance problem. While sharding a database that large is a pain it seems inevitable. My question is, has anybody successfully implemented EF with a sharded database and, if so, do you have any guidance? 回答1: Have you investigated the following options: Clustering your DB (I assume