entity-framework-4.1

Entity Framework 4.1 Code First approach to create many-to-many relation

旧时模样 提交于 2019-12-06 21:32:29
问题 I'm using the Silverlight 5 Beta SDK and the EntityFramework 4.1 in an Silverlight Application. I'll try to create the two tables 'Author' and 'Book'. In SQL, there should be a third (join) table, which makes the many-to-many relation between Author and Book (one author could have written many books and a book could be written from many authors). This is what I've got so far: namespace CodeFirst.Models.Web { public class Author { public Author() { this.Books = new HashSet<Book>(); }

EntityFramework4.1's .Local().ToBindingList() , How to filter then?

眉间皱痕 提交于 2019-12-06 20:16:18
问题 Example Model: Customer -> Order contex.Order.Load(); orderBindingSource.DataSource = context.Order.Local().ToBindingList(); Then, how to filter? e.g. context.Order.Where(m=>m.customerID > 1) I want to get the BindingList implementation that stays in sync with the ObservableCollection returned by the Local property. 回答1: Have you tried using select? contex.Order.Load(); orderBindingSource.DataSource = context.Order.Local().Select( m => m.customerID > 1).ToBindingList(); Edit Not entirely sure

Entity Framework 4.2 - How to realize TPT-Inheritance with Database-generated Primarykey Value?

╄→гoц情女王★ 提交于 2019-12-06 15:19:45
I want to use the EF (4.2) in the following scenario: There exists a database already (so I chose the database-first approach) and it is a SQL Anywhere DB. I want to use persistence-ignorant business objects, so I use the DbContext Template to generate POCO classes from the EDM. There is one simple inheritance hierarchy among my entities: an abstract base entity and two concrete derived entities. In the database there is one table for each type of the inheritance hierarchy (Table-Per-Type Strategy). Each of these three tables has a primary key column ( Id , type: integer ), and the association

OData:Wildcard (startswith) filtering for number (ID) fields in the url request

这一生的挚爱 提交于 2019-12-06 15:08:20
I've been researching a way to perform fuzzy searches for my numerical ID fields of my entity via OData and JavaScript. So far, I have not found the answer I am looking for. I can filter other edm.string columns perfectly using the "Startswith" filter option, however when i attempt to pass in any other non-string type, I get a type error response from the server back. In applications that I control the database, I was successfully able to get around this, by creating views I need and converting the numerical type of the view to a string. However, this seems a bit overkill to go out of my way

EF CTP5 - Context Inheritance Across Multiple Assemblies

一曲冷凌霜 提交于 2019-12-06 14:40:16
I have two assemblies, each with models and a model context. The first assembly model context is derived from DbContext. The second assembly model context is derived from the first assembly model context. This works, except the database generation fails because the first assembly models aren't considered when generating the database. Is there a way to ensure that the first assembly models are properly considered during database generation? I solved this by loading the other assembly's metadata into the underlying ObjectContext's MetadataWorkspace within the context's constructor: namespace

Entity Framework 4.1 reverse engineering code-only

廉价感情. 提交于 2019-12-06 14:33:43
I am using Entity Framework 4.1 and want to take advantage of their code-only approach. In the video located at http://channel9.msdn.com/Events/TechEd/Europe/2010/DEV212 starting at 35:00 minutes in they show a tool that reverse engineers their POCOs from their existing database. I want to do this as I have an existing database. I have installed EF 4.1 and I can create POCO entities just fine but I can't seem to find the tool they used to create POCOs from the existing database. Was this tool not released with 4.1? Thanks in advance. The tool is called EF Power Tools CTP1 . If your database is

Pluggable Conventions in Entity Framework

烂漫一生 提交于 2019-12-06 12:57:38
I am following EF Feature CTP5: Pluggable Conventions to create custom pluggable convention (in this particular case to change the precision of all decimal fields). Looks like in the latest release of EF the Add method on ConventionsConfiguraions is also "internal'. How do i add custom Pluggable Conventions now? The feature has been removed in EF 4.1 and a possible implementation postponed to a later release: Code First customizable (pluggable) conventions are not supported. Removing the default Code First conventions is supported. Quote from here: http://msdn.microsoft.com/en-us/library

Define relationships for hierarchical data in Entity Framework Code First

旧巷老猫 提交于 2019-12-06 12:37:30
I have a hierarchical relationship defined for one of my tables where the relationship is stored in a separate join table. The join table also contains information about the type of relationship. The (simplified) schema looks like: Bills ID int IDENTITY(1,1) NOT NULL (PK) Code varchar(5) NOT NULL Number varchar(5) NOT NULL ... BillRelations ID int IDENTITY(1,1) NOT NULL (PK) BillID int NOT NULL RelatedBillID int NOT NULL Relationship int NOT NULL ... I have FK relationships defined on BillID and RelatedBillID to ID in the Bills table. I'm trying to map this in Entity Framework Code First with

Client Side validation in MVC 3 Database First

[亡魂溺海] 提交于 2019-12-06 11:09:22
If I add [Required] in my entity class then unobtrusive validation works fine. [Required] is not added where I generate my entity class using database first(*.edmx). If I manually add [Required] in my entity property, something like [Required] public int {get;set;} [Required] will delete when I update my edmx. So my question is how can I perform client side validation if I use database first in EF. Create a partial class for your entity and use the MetadataType attribute. See example below: [MetadataType(typeof(MyEntity.Metadata))] public partial class MyEntity { private sealed class Metadata

Entity Framework 4.1 DbContext generator problems

心不动则不痛 提交于 2019-12-06 11:04:20
I am new to Entity Framework 4.1 and I really wanted to transition to POCO classes for my model. I found that this was very easy using the "DbContext Generator" item provided when you install EF 4.1. It did exactly what I wanted it to do and generated the DbContext object and all the POCOs for my existing EDMX model. I ran the app and tested that it was still working. It was. Happy with this I deleted the EDMX file and the T4 templates and began reorganizing my new POCOs. However, after getting it to build properly again I encountered a runtime problem. When instantiating the DbContext it is