entity-framework-ctp5

Code first - how can I save an ICollection when I'm not setting the parent object to EntityState.Modified?

余生长醉 提交于 2019-12-03 16:30:04
If I have the below class: public class Foo() { public int PropertyIWantUpdated {get; set;} public int PropertyIDontWantUpdated (get; set} public ICollection<Bar> Bars {get; set;} } When saving to my db, instead of context.Entry(thisFoo).State = EntityState.Modified; I'm using context.Entry(thisFood).Property(tf => tf.PropertyIWantUpdated).IsModified = true; how can I also save changes to Bars? Ladislav Mrnka It depends what you are trying to update. First of all let me clarify one important fact - if you have detached entity graph (more entities with relation) and you want to pass all changes

Entity Framework 4 - Mapping non-public properties with CTP5 (code first) in a persistence unaware context

£可爱£侵袭症+ 提交于 2019-12-03 11:19:39
I know the question already has a solution (eg. this question ) but I really can't afford to attach the mapping logic in the same assembly where the domain (POCO classes) is. Is there any other way? I found this nice blog post but I couldn't get it working. Here is the model: public class Institute { /** Code omitted **/ protected virtual ICollection<InstituteText> InnerInstituteTexts { get; set; } private InstituteTextSet _TextSets; public InstituteTextSet Texts { get { if (_TextSets == null) _TextSets = new InstituteTextSet(InnerInstituteTexts); return _TextSets; } } } Mapping code: var

entity framework custom data type mapping

会有一股神秘感。 提交于 2019-12-01 19:24:48
Given this code: public class Car { public virtual int CarId { get; set; } public virtual string TypeName { get; set; } public ConvertableNullable<double> Price { get; set; } } Where the ConvertableNullable is just a workaround to Nullable , but it doesn't inherit from it. Now, this my simple context, where i map, the car class to entity, and map every property of it public class MyDBContext : DbContext { public MyDBContext() : base( "data source=.;initial catalog=newDB1;integrated security=True;" + "multipleactiveresultsets=True;App=EntityFramework") { } protected override void

how to do many to many with the same table with EF4 Code First

拈花ヽ惹草 提交于 2019-11-30 18:58:16
I have this schema: create table Person ( id int identity primary key, name nvarchar(30) ) create table PersonPersons ( PersonId references Person(id), ChildPersonId references Person(id) ) how to create the classes to map them using EF4 Code First CTP5 ? Brian Kretzler For the POCO... class Person { public Guid PersonId { get; set; } public virtual Person Parent { get; set; } public virtual ICollection<Person> Children { get; set; } } ...set up the mapping in the DbContext... protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<Person>() .HasOptional(entity

Turn Off Object Caching in Entity Framework CTP5

狂风中的少年 提交于 2019-11-30 16:52:54
问题 I am having trouble figuring out something with the Entity Framework Code First stuff in CTP 5. It is doing caching of objects and I don't want it to. For example, I load a page (working with an ASP.NET MVC site) which loads an object. I then go change the database. I re-load the page and the changes are not reflected. If I kill the site and rerun it then it obviously re-fetches. How do I, either generally for a type, or even for a particular query, tell it to always go get a new copy. I

Entity Framework CTP5 - How to Call Stored Procedure?

空扰寡人 提交于 2019-11-30 15:00:52
问题 This may be a simple answer, but i can't see how to execute a stored procedure with EF CTP5. In Entity Framework 4.0, we did this: ExecuteFunction("ContainerName.StoredProcName", new ObjectParameter("Id", id)) . Which is a method on the ObjectContext . But DbContext has no such method. How do we call a stored proc? Is it not supported in EF CTP5? EDIT: I found this thread, which states you need to do this: var people = context.People.SqlQuery("EXECUTE [dbo].[GetAllPeople]"); This raises some

EF4 Code First make tables names singular

与世无争的帅哥 提交于 2019-11-30 14:52:46
问题 I'm using standards for singular table names. EF4 Code First has by default to pluralize table names. I have put the code to override this convention, but seems is not working. using section: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.ComponentModel.DataAnnotations; using System.Data.Entity; using System.Data.Entity.Database; using System.Data.Entity.ModelConfiguration; using System.Data.Entity.ModelConfiguration.Conventions.Edm; Data

Entity Framework CTP5 - How to Call Stored Procedure?

删除回忆录丶 提交于 2019-11-30 13:13:24
This may be a simple answer, but i can't see how to execute a stored procedure with EF CTP5. In Entity Framework 4.0, we did this: ExecuteFunction("ContainerName.StoredProcName", new ObjectParameter("Id", id)) . Which is a method on the ObjectContext . But DbContext has no such method. How do we call a stored proc? Is it not supported in EF CTP5? EDIT: I found this thread , which states you need to do this: var people = context.People.SqlQuery("EXECUTE [dbo].[GetAllPeople]"); This raises some concerns: 1) You are now calling a stored prodedure on the set , not the context . Stored procedures

Can I access the discriminator value in TPH mapping with Entity Framework 4 CTP5

跟風遠走 提交于 2019-11-30 11:49:30
Using Entity Framework 4 CTP5 Code First and this example Is it possible to access the discriminator value? I would like to use it in a projection like context.BillingDetails.Select(x => new { Number = x.Number, DiscrimitatorValue = /* how do I get the discriminator value? */ }); From this post I understand the discriminator cannot be mapped to a property but is there any other way of accessing it? I may be late to the game on this one, but I just added a getter property to the base class that returned the name of the current type: public string DiscriminatorValue { get { return this.GetType()

How to join tables in EF LINQ

て烟熏妆下的殇ゞ 提交于 2019-11-30 08:56:25
When I try to join tables var query = from foo in db.Foos from bar in db.Bars where foo.ID == bar.FooID where foo.ID == 45 select bar; query.toArray() I get such error Unable to create a constant value of type 'Bar'. Only primitive types ('such as Int32, String, and Guid') are supported in this context. Try that instead: var query = from foo in db.Foos join bar in db.Bars on foo.ID equals bar.FooID where foo.ID == 45 select bar; Anyway, I suggest you model the relation between Foo and Bar in the EDM designer, this way you don't need an explicit join: var query = from foo in db.Foos where foo