ef4-code-only

How map objects to a view with EF 4 code first?

筅森魡賤 提交于 2019-12-28 06:18:16
问题 How can you map an entity to a database view with EF 4 code first? Is there a way to do this by deriving from the EntityConfiguration classes? 回答1: Yes! I found the answer: You can certainly use Code First to map to a view, just tell Code First that it's a table and it will use the same SQL against the view that it would for a table. Obviously if your view isn't writeable then saving is going to fail if you try and update values in the entities that are based on the view, but we will just

How do I get the raw SQL underlying a LINQ query when using Entity Framework CTP 5 “code only”?

纵饮孤独 提交于 2019-12-20 17:48:09
问题 I've using Entity Framework CTP5 in "code only" mode. I'm running a LINQ query on a object that was return from the database, as the query is running really slowly. Is there any way in which I can get the SQL statement that is being generated from the query? Topic currentTopic = (from x in Repository.Topics let isCurrent = (x.StoppedAt <= x.StartedAt || (x.StartedAt >= currentTopicsStartedAtOrAfter)) where x.Meeting.Manager.User.Id == user.Id && isCurrent orderby x.StartedAt descending select

How do I get the raw SQL underlying a LINQ query when using Entity Framework CTP 5 “code only”?

若如初见. 提交于 2019-12-20 17:48:09
问题 I've using Entity Framework CTP5 in "code only" mode. I'm running a LINQ query on a object that was return from the database, as the query is running really slowly. Is there any way in which I can get the SQL statement that is being generated from the query? Topic currentTopic = (from x in Repository.Topics let isCurrent = (x.StoppedAt <= x.StartedAt || (x.StartedAt >= currentTopicsStartedAtOrAfter)) where x.Meeting.Manager.User.Id == user.Id && isCurrent orderby x.StartedAt descending select

Entity Framework 4: Code First - Creating db in another schema? MapSingleType?

久未见 提交于 2019-12-18 12:16:08
问题 I have a database and i using 2 different schemas. Schemas are like namespaces (correct me if i am wrong). This way i have 1 db and currently 2 schemas... so the tables in 1 schema can be named the same as the tables in the other schema because they are in separate schemas. How do i get EF Code first to talk to a different schema and not the default schema? Is it somethign to do with MapSingleType and overriding a method or can i do something else? ANy help really appreciated. 回答1: You can

How not persist property EF4 code first?

痞子三分冷 提交于 2019-12-17 16:23:55
问题 How do I make non persisted properties using codefirst EF4? MS says there is a StoreIgnore Attribute, but I cannot find it. http://blogs.msdn.com/b/efdesign/archive/2010/03/30/data-annotations-in-the-entity-framework-and-code-first.aspx Is there a way to set this up using EntityConfiguration? 回答1: In EF Code-First CTP5, you can use the [NotMapped] annotation. using System.ComponentModel.DataAnnotations; public class Song { public int Id { get; set; } public string Title { get; set; }

Fluent API, EF 4.1: a problem of inheritance and foreign key

百般思念 提交于 2019-12-13 00:14:13
问题 There are several simple classes: The first class: public class User { public int UserId { get; set; } public string Username { get; set; } // ... public ICollection<Topic> Topics { get; set; } } The second class: public class Publication { public int PublicationId { get; set; } public string Title { get; set; } / ... public User Author { get; set; } } The third class: public class Topic: Publication { public string TopicContent { get; set; } // ... } After creating a database for my model I

EF4 CTP5 self-referencing hierarchical entity mapping

廉价感情. 提交于 2019-12-12 08:16:27
问题 Okay, this should be really easy, but I've been tearing my hair out. Here's my POCO (which has to do with machine parts, so a part can be contained within a parent part): public class Part { public int ID { get; set; } public string Name { get; set; } public Part ParentPart { get; set; } } When the database table is created, the column names are "ID", "Name", and "PartID". How do I change the name of that last column to "ParentPartID"? 回答1: Basically, you want to rename the foreign key in an

EF4 CTP5, mapping different entities to the same (existing) table

痴心易碎 提交于 2019-12-11 05:22:17
问题 By code-first approach (but with an existing db schema), we are trying to map 2 different entities (Customer and Resource) to the same table. Both entities has the same keys and mapping. However, when running the app, we have a runtime error telling us that mysterious message: System.InvalidOperationException: Type 'Resource' cannot be mapped to table 'CLIENT' since type 'Customer' also maps to the same table and their primary key names don't match. Change either of the primary key property

Use a struct in place of a primitive for a EF4 property type

南笙酒味 提交于 2019-12-10 13:33:48
问题 I've got an EF4 entity (code-first) that includes an int bitmask. I've created a Bitmask struct to make working with bitmasks easier (provides bool properties to access the bits). The bitmask struct includes overloaded implicit operators for converting to and from an int. I tried setting the property type to the bitmask struct but the value is coming back as 0. I know the value in the database has a value and the bitmask works in my unit tests. I set the HasColumnType to "INT". The property..

load partial entityset ef4

自古美人都是妖i 提交于 2019-12-08 06:51:02
问题 Can I load only a few properties from an Entity? As an example I have an entity with the following properties: ID DESCRIPTION HEADER PICTURE I only want to load the IDs and not the other properties. How can I do this? 回答1: In your case if you just need the ID s, you can use the following query: var ids = context.YourEntities.Select(e => e.ID).ToList(); You can also use projection (useful if you need to load more than one property): var entitiesWithIdsAndHeaders = context. YourEntities. Select