entity-framework-ctp5

Using Entity Framework Code First CTP5, how do I create a primary key column that are INTs and are not identity columns

喜欢而已 提交于 2019-12-29 06:34:07
问题 Using Entity Framework Code First CTP5, how do I create a primary key column that are INTs and are not identity columns Preferably not using attributes. 回答1: If you're building your entities using the fluent interface rather than using attributes over the properties, you may be able to use the DatabaseGenerationOption class (from EntityFramework.dll, in the System.ComponentModel.DataAnnotations namespace). I've not tested it, but this is what it would look like: modelBuilder .Entity<Foo>()

Generate money type fields using code first EF CTP5

浪尽此生 提交于 2019-12-28 06:17:07
问题 In this blog post: EF4 Code First Control Unicode and Decimal Precision, Scale with Attributes, Dane Morgridge used attributes to control the creation of different types on your database. ...And I found this pretty unique BTW!!! How do I generate money type fields in my resulting database using code first API of EF CTP5, if is possible to do it from your model, using conventions or attributes? Sorry about my English is not my main language. Thanks in advance. 回答1: For example, consider this

EntityFramework CTP5 change tracking

假装没事ソ 提交于 2019-12-24 07:03:27
问题 I am trying to reproduce the same behavior as EntityObject using CTP5 DBContext for change tracking. Consider the tables Movie and Director. Relationship is only 1 director for a movie and multiple movies for each director. var movie = new Movie(); movie.Name = "ABCD"; ctx.Movies.Add(movie);//ctx.Movies.AddObject(movie); movie.Director = new Director() { Name = "dir1" }; var existingDirector = ctx.Directors.Where(a => a.Name == "dir2").FirstOrDefault(); movie.Director = existingDirector; ctx

Entity Framework 4.1 - How to “Force” EF To Go To DB Instead of Using Graph?

混江龙づ霸主 提交于 2019-12-23 09:17:35
问题 Here's the scenario, i have a website, which in a single HTTP request (HTTP POST), i need to do the following: Grab an object (let's say "Tag") Save some other object (let's say "Question") Get a fresh copy of "Tag". Redirect to another page, which needs a fresh copy of "Tag". Behind the scenes, 2) involves database-side triggers that affects data on "Tag". So when i do 3), EF is pulling the same copy of the object from step 1), since it's in the graph/internal memory (e.g same connection

EF Linq to entities query generating UNION for TPC CTP5 code-first entity

青春壹個敷衍的年華 提交于 2019-12-22 08:52:33
问题 I have the following entities: public class User { public int Id { get; set; } public string Name { get; set; } } public class HappyUser : User { public bool IsHappy { get; set; } } I am configuring the entities using Table Per Concrete Type (TPC) in order to generate a User table and a HappyUser table. I want the HappyUser table to include the properties of the User class, and I don't want any relationship between the two tables. I configure the entities as follows: public class UserTest :

EF Code-First - Mapping stored procedures

时光总嘲笑我的痴心妄想 提交于 2019-12-22 08:28:47
问题 I'm trying to implement nested sets in my database model. To make it easy to use I would like to create stored procedures for insert/update/delete operations on my tree nodes to keep my tree in a valid state. Is it possible to create mapping of the stored procedures in the current version of code-first model? I mean that my stored procedures will be called when for example, new entity will be added to the dbcontext. 回答1: Code First in Entity Framework does not support Stored Procedure by

How can i ignore a DbUpdateConcurrencyException with my Entity Framework code?

旧巷老猫 提交于 2019-12-21 04:02:21
问题 Is there any way I can tell EF to not worry about the number of rows a DELETE or UPDATE do or don't do? I'm trying to delete a row from the database, but because the row doesn't exist, EF throws an exception: DbUpdateConcurrencyException .. saying 0 rows were affected . This is right -> no rows were deleted. But that's totally fine .. cause there's no data. I don't really want to do a round-trip to the DB to see if that row exists .. and if so .. then try and delete it. If i try and swallow

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

南笙酒味 提交于 2019-12-21 03:46:12
问题 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)

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

烂漫一生 提交于 2019-12-21 03:46:03
问题 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)

Entity Framework CTP5 - Reading Multiple Record Sets From a Stored Procedure

谁都会走 提交于 2019-12-20 19:07:53
问题 In EF4, this was not easily possible. You either had to degrade to classic ADO.NET (DataReader), use ObjectContext.Translate or use the EFExtensions project. Has this been implemented off the shelf in EF CTP5? If not, what is the recommended way of doing this? Do we have to cast the DbContext<T> as an IObjectContextAdapter and access the underlying ObjectContext in order to get to this method? Can someone point me to a good article on doing this with EF CTP5? 回答1: So i got this working, here