entity-framework-ctp5

Entity Framework: Set Delete Rule with CodeFirst

纵饮孤独 提交于 2019-11-27 20:35:25
I am using EF4 CTP 5, CodeFirst. Please see my classes first: public class Guest { [Key] public Guid GuestID { get; set; } public Language PreferredLanguage { get; set; } public Guid? LanguageID { get; set; } } public class Language { [Key] public Guid LanguageID { get; set; } [Required(ErrorMessage = "Enter language name")] [StringLength(50, ErrorMessage = "Language name is too long")] public string LanguageName { get; set; } // in origine language } My goal is to set a certain "Delete Rule" for the Guest-Language relationship. When a language is deleted, I do not want to delete the

Problem with Eager Loading Nested Navigation Based on Abstract Entity (EF CTP5)

▼魔方 西西 提交于 2019-11-27 15:18:38
问题 I a portion of my EF model that looks like this: Summary: Location has many Posts Post is an abstract class Discussion derives from Post Discussions have many Comments Now, the query i'm trying to achieve: Get information about Location Id 1234, including any Discussions and Comments associated with those Discussions. I can get discussions and the comments like this: var discussions = ctx.Posts .OfType<Discussion>() .Include(x => x.Comments) .ToList(); But i can't seem to get it based on the

Adding index to a table

≡放荡痞女 提交于 2019-11-27 14:27:35
I have a table Person : id, name I often have queries like: select * from Person where name Like "%abc%". I have 2 questions: How do I implement this query using code-first 5 (CTP5) How do I add an index on the name column to make data retrieval faster based on name like in the query? Like operator can be performed with Contains function: var query = from p in context.Persons where p.Name.Contains("abc") select p; Index must be added by SQL - there is no special construction in EF to create index. You can execute this SQL from DB initialization. First you must implement custom initializer:

Refresh entity instance with DbContext

ε祈祈猫儿з 提交于 2019-11-27 11:39:53
With EF4 CTP5 DbContext, what is the equivalent of this public void Refresh(Document instance) { _ctx.Refresh(RefreshMode.StoreWins, instance); } I've tried this but it doesn't do the same thing, updating the instance public void Refresh(Document instance) { _ctx.ChangeTracker.DetectChanges(); } ? You must use this: public void Refresh(Document instance) { _ctx.Entry<Document>(instance).Reload(); } The above doesn't work. Reload() method does not correctly refresh the entity from the database. It performs SQL select query but does not build proxies for the navigational properties. See the

Entity Framework Code First: How can I create a One-to-Many AND a One-to-One relationship between two tables?

北战南征 提交于 2019-11-27 04:24:29
Here is my Model: public class Customer { public int ID { get; set; } public int MailingAddressID { get; set; } public virtual Address MailingAddress { get; set; } public virtual ICollection<Address> Addresses { get; set; } } public class Address { public int ID { get; set; } public int CustomerID { get; set; } public virtual Customer Customer { get; set; } } A customer can have any number of addresses, however only one of those addresses can be a mailing address. I can get the One to One relationship and the One to Many working just fine if I only use one, but when I try and introduce both I

Circular Reference exception with JSON Serialisation with MVC3 and EF4 CTP5w

久未见 提交于 2019-11-27 03:53:55
问题 I'm having problems with a circular reference when i try and serialise an object returned via EF4 CTP5. Im using the code first approach and simple poco's for my model. I have added [ScriptIgnore] attributes to any properties that provide a back references to an object and annoyingly every seems to work fine if i manually instantiate the poco's, i.e. they serialise to JSON fine, and the scriptignore attribute is acknowledged. However when i try and serialise an object returned from the DAL i

generic repository EF4 CTP5 getById

北慕城南 提交于 2019-11-26 21:30:43
问题 I have a generic repository an I am trying to add a GetById method as shown here C# LINQ to SQL: Refactoring this Generic GetByID method The problem is my repository does not use System.Data.Linq.DataContext instead I use System.Data.Entity.DbContext So I get errors where I try to use Mapping.GetMetaType and return _set.Where( whereExpression).Single(); How can I implement a generic GetById method in CTP5? Should I be using System.Data.Entity.DbContext in my Repository. Here is the start of

Using mvc-mini-profiler database profiling with Entity Framework Code First

亡梦爱人 提交于 2019-11-26 20:26:11
I'm using the mvc-mini-profiler in my project built with ASP.Net MVC 3 and Entity Framework code-first. Everything works great until I attempt to add database profiling by wrapping the connection in the ProfiledDbConnection as described in the documentation. Since I'm using a DbContext, the way I am attempting to provide the connection is through the constructor using a static factory method: public class MyDbContext : DbContext { public MyDbContext() : base(GetProfilerConnection(), true) { } private static DbConnection GetProfilerConnection() { // Code below errors //return

Entity Framework: Set Delete Rule with CodeFirst

拈花ヽ惹草 提交于 2019-11-26 20:24:05
问题 I am using EF4 CTP 5, CodeFirst. Please see my classes first: public class Guest { [Key] public Guid GuestID { get; set; } public Language PreferredLanguage { get; set; } public Guid? LanguageID { get; set; } } public class Language { [Key] public Guid LanguageID { get; set; } [Required(ErrorMessage = "Enter language name")] [StringLength(50, ErrorMessage = "Language name is too long")] public string LanguageName { get; set; } // in origine language } My goal is to set a certain "Delete Rule"

Refresh entity instance with DbContext

旧巷老猫 提交于 2019-11-26 18:04:26
问题 With EF4 CTP5 DbContext, what is the equivalent of this public void Refresh(Document instance) { _ctx.Refresh(RefreshMode.StoreWins, instance); } I've tried this but it doesn't do the same thing, updating the instance public void Refresh(Document instance) { _ctx.ChangeTracker.DetectChanges(); } ? 回答1: You must use this: public void Refresh(Document instance) { _ctx.Entry<Document>(instance).Reload(); } 回答2: The above doesn't work. Reload() method does not correctly refresh the entity from