Entity framework 4 EF4 - Can a POCO be used as both an Entity and ComplexType?

I am using EF4 CTP5. Here are my POCOs: public class Address { public int Id { get; set; } public string Name { get; set; } public string Line1 { get; set; } public string Line2 { get; set; } public string City { get; set; } public string State { get; set; } public string PostalCode { get; set; } } public class Customer { public int Id { get; set; } public string Name { get; set; } public List<Address> Addresses { get; set; } public List<Or

Entity framework 4 how to use my own custom classes with entity framework?

i am very much new to Entity Framework and i just used this in nop commerce 1.9 so i dont know how to implement Entity Framework from scratch for a new project. i created the database with all table and make complete relationship in all table. and also created the project for my class an example of a class is class BE_Room { #region properties public int RoomId { get; set; } public string RoomType { get; set; } public string Description { get; set; }

Entity framework 4 EntityState.Detached, do I need to reload?

All, Using .Net 4 and EF 4.4 Database First. Let's say I have a DbContext. I load data from this DbContext, do stuff, and then detach everything from the DbContext and dispose of the DbContext. Then, I create a new DbContext (same model) and load other data that overlaps with data from the first DbContext. Do I need to, prior to executing my query, do Entry().Reload() or will the Detatched Entities refresh automatically when they're loaded into the new context. The reason I ask is because

Entity framework 4 How to get primary key field name for null EntityReference?

I've made the following function to assign value to a foreign key reference (I know, it's dirty and does not work for compound keys): void setFk(dynamic tbl,object id){ var path=db.DefaultContainerName+"."+tbl.TargetRoleName; var ret=new System.Data.EntityKey(path, tbl.RelationshipSet.ElementType.RelationshipEndMembers[0].GetEntityType().KeyMembers[0].Name, id); tbl.EntityKey=ret; } which I want to invoke by this: setFk(newRec.WorkItemsRefer

Entity framework 4 Catel Extensions EntityFramework5

I'm using the Catel Extensions EntityFramework5 for repository and unit of work pattern. I'm trying to implement repository for a derived class DailyMacroValue where DailyMacroValue :DailyPrice there is the code: public class DailyMacroValueRepository :EntityRepositoryBase<DailyMacroValue, int>, IDailyMacroValueRepository { private XXXEntities _dbContext; public DailyMacroValueRepository(DbContext dbContext) : base(dbContext) { _dbConte

Entity framework 4 Model compatibility cannot be checked because the database does not contain model metadata. Model

I a tiring to upload excel sheet and insert data in MySQL database. when I debug I am getting below error: Model compatibility cannot be checked because the database does not contain model metadata. Model compatibility can only be checked for databases created using Code First or Code First Migrations. Below my code: enter code here protected void Application_Start() { AreaRegistration.RegisterAllAreas(); Database.SetInitializer<EFDbContext>(new UploadUsingE

Entity framework 4 Entity Framework: Storing all contact details in the one table (association,compound FKs)

My database stores three types of user: Agent, Programmer and Employee. All three types of user will have an address, a telephone number, a fax number, etc..., so to minimize table count, I want to create a table tbContactDetails, and use this to store the contacts details of these 3 types of user. My tbContactDetails, which looks like this: tbContactDetails int ContactId (PK, FK) int ContactType (FK) (1=Agent, 2=Programmer, 3=Employee) char (50) Addresses etc... The field ContactType dete

Entity framework 4 Entity Framework Update statement generating invalid SQL for Firebird

I'm using Firebird 2.5.0 with the Entity Framework, which has been working well. However, recently I have changed something (I presume) and now the SQL that is being generated when I try to save my changes is not valid for Firebird: update ( select [fields] from [table]) set [field] = @p0 where ([keyfieldn = @pn]) As far as I know, Firebird 2.5.0 does not support this syntax, and when I try to save changes I get back a SQL error that says as much ( "Token unknown, column 8: (" ) I'm not sure

Entity framework 4 How to create a function import/stored procedure with EDM that includes reference entities

Does anybody know how to create a function import in an Entity Data Model that returns a collection of entity types that also includes the reference types. For instance, in LINQ to entities you can use the .Include() method to load a certain referenced entity from the DB. I have a stored procedure that returns data from two tables and I want to populate both entity objects from this stored procedure, but when I step through the wizard to create the function import, it only gives the option of cr

Entity framework 4 Saving to a many to many relationship

The problem am facing is, anytime I call events.Tags.Add(tag) and call Save changes on the context, it ends up creating a new tag info in the Tags table instead of just inserting the EventId and TagId into just the EventTags Table. Base on the data below how do I add an event and tag into the EventTags Table. Lets say I want to add Event with Id=2 and and tag with Id =1 to the EventTags table. I have the following entities. public class Event { public int Id { get; set; }

Entity framework 4 Entity framework along with plain old ADO.Net

I am building a new applications architecture and I need your advice. We have a central MSSQL server database hosted as SQL Azure. This database needs to be accessed from many different applications, most of them are web applications hosted in windows azure and couple of them are winforms apps. Accessing database for web application is straight forward with ADO.Net. For winforms applications, the wcf data services technology seems impressive along with client authentication services for securit

Entity framework 4 Entity Framework 4 code-based migrations don´t work after calling CreateDatabaseIfNotExist

I have a MVC 3 project were I use code based migrations together mith automatic migrations(this works). When I install this project on a new server the database is created by CreateDatabaseIfNotExist initializer, cause I´m using the seed method of this. After executing this I have a __MigrationHistory table with one entry. The model hash of this entry is exactly the same like the last one from my developement server. On my development server I have an entry for each of my code based migration i

Entity framework 4 Entity framework 4 - Table with Identity column addition

I have a table defined in a SQL Server database as follows Columns MID Int foreign Key MRUOMID Int foreign Key All columns in this table are foreign keys and referring to other entities. I wish to add an Identity column to this table. If I do so and update the EDMX model from the database, I get the following error. problem in mapping fragments starting at 7462. You must specify mapping for all key properties. I need an identity column to be added which I can refer to in my Enti

Entity framework 4 How to lower number of queries that EF4 sends to DB?

I use the following code to remove all KlientDoTrasa assigned to trasaOriginal and then create and assign new KlientDoTrasa based on collection: trasaToEdit.Klienci. In my test case assigned KlientDoTrasa and new KlientDoTrasa are the same, so I thought EF4 should not send any query to database, but it sends, first deletes then inserts. Is there a way to limit it? public void Edit(int trasaId, TrasaEditViewModel trasaToEdit) { Trasa trasaOriginal = _trasaRepository.FindById(trasaId); t

Entity framework 4 Domain Modeling and Mapping with EF CPT5

I am trying to model out a album that has a collection of photos. Each Album will have a collection of Photos and a Photo that is a thumb. This is what I have but EF does not seem to like it. I am using EF CPT5 The Model: public class Album : IEntity { private DateTime _dateCreated; public Album() { _dateCreated = SystemTime.Now(); Photos = new List<Photo>(); } public long Id { get; set; } public string Name { get; set; } public string Location { get; set; } public

Entity framework 4 Is there any way to know if EF4 is currently in the processes of hydrating an Self Tracking Entity (STE)

I have the need to perform some custom logic in my EF 4 STE public getters and setters. However, I only want this custom logic to execute if EF is not currently hydrating an entity. Are there any built in flags, statuses or object states that can be checked to determine if EF is currently in the act of hydrating a STE entity on my behalf? I am not doing lazy loading, so we perform all our data loading in one shot. I'm hoping I don't have to change the Entity T4 templates to add the infrastru

Entity framework 4 EF4 CTP5 - HasColumnType not working

I want to override the default nvarchar(4000) for one of my string columns to a text data type in SQL Express. I use this code. modelBuilder.Entity<Accommodation>() .Property(p => p.Information) .HasColumnType("text"); But the column type remains as nvarchar? I also asked here http://social.msdn.microsoft.com/Forums/en/adonetefx/thread/a1d84ea9-2f8e-42f0-bb83-ac9f68805d6d?prof=required

Entity framework 4 What is the scope of my Ninject injected ObjectContext in my custom MembershipProvider (using Request scope)?

I use Entity Framework 4 and ASP.NET MVC 3. I made a custom membership provider and use Ninject to inject an EFAccountRepository into it (Bound IAccountRepository to EFAccountRepository). This account repository has an ObjectContext injected into it. I also use this repository (and others) in my controllers. For this reason when I bound IContext to my ObjectContext, I set the scope to "per request" so the ObjectContext only lives in one request and is shared between the repositories. I am som

Entity framework 4 Update db from Excel with Entity Framework 4.1

I'm new to EF 4.1 and try to move some code from to EF 4.1 (code first). Here is some background. I'm managing products for several companies, so I have a table "Product" with a column called "Company". I need to update (insert if not exist, otherwise update) this table from an Excel file containing products for a given company(let's say C1). Here is what I'm doing (using proprietary db access code and LINQ) : Retrieve all products for company C1 as a list of products For each product appearin

Entity framework 4 Entity Framework and LLBLGen

I have a database, which has two tables. The Order table, and the Item table. The relationship is m:1. I am using LLBLGen as the mapping tool to generate the source file. I can see that the ItemID from the Item table is displayed in the Order entity from the designer of LLBLGen, which is correct. However, when I try to call this generated source codes, the ItemID is not listed as a property of my Order class. Actually all my foreign key is gone. Could anyone teach me how to generate the fo

Entity framework 4 Why is MSpec reporting false positive when using Entity Framework 4?

I'm trying to write some Mspec tests against some EF4 objects. However they are returning false positives. I don't know if it is the way that I've written the tests or if there is something else going on. The test class is below: [Subject(typeof (Product))] public class When_loading_a_known_product { protected static Product product; protected static ProductDbContext dbContext; Establish context = () => { dbContext = new ProductDbContext(ConnectionStringProvider.Get

Entity framework 4 Entity Framework 4.3.1 and SQL Server CE

I am following the official tutorial "EF 4.2 Model & Database First Walkthrough" using SQL Server CE 3.5 and alternative 4.0 versions. Unfortunately I always get an error: EntityException {"The underlying provider failed on Open."} on db.SaveChanges() command. Why MS have such poor support for its own database?

Entity framework 4 why two new entities are associated automatically in Entity Framework with POCO classes

I am learning the usage of POCO classes and relationships between entities. I have two tables. And I created Data Model, and POCO classes for them. But when I tried to add a new Vehicle entity and a new Journey at the same time before calling context.SaveChanges(), those two new entities will be associated automatically. That means, the new Journey record will have its VehicleId field populated with Id of the new Vehicle record. But when I switched to entity classes generated by Data Model, th

Entity framework 4 entity framework- iterate into multiple tables using a table

I am trying to access tables in entity framework using another table, but i am getting tables as null. e.g. I am having 3 tables A,B and C. And A is having FK(Foreign key) of B and B is having FK of C. I am having object of A. Now I want to access C using B. means A.B.C. But i am getting B as null. So please give me the solution for this. var a= databaseContext.A.Find(Id); var c=a.B.C.where(x=>x.Id==SomeId); Thanks in advance. Update: Tables Commitment CommitmentId(PK) FinancialYear

Entity framework 4 Entity Framework with Poco and navigation properties

I am using Poco Generator with entity framework, And Poco Proxy class have been generated successfully, For a single table all the things goes fine, herein I've listed the main part of my classes and explain relations between tables. There are 3 table that they have many-to-many relation as follows: 1- Authority 2- Ability 3- AuthorityAbilityMap Each Authority can have many Ability and vice verse. The main problem is that Navigation property in Authority Class doesn't work. The Authority cl

Entity framework 4 Problem mapping one to many relationship with EF CTP4

I am trying to define a one to many relationship between Category and Project (a Category can have one or many Projects, a Project can have one or no Category) public class Project : Entity { public virtual string Title { get; set; } public virtual Guid? CategoryId { get; set; } public virtual Category Category { get; set; } } public class Category : Entity { public virtual string Name { get; set; } public virtual ICollection<Project> Projects { get; set; } }

Entity framework 4 Adding computed column to EF 4.0 Model

I want to add an association to an EF 4.0 model that uses two constant properties as part of what would be the referential constraint. Obviously it's no good adding the properties into the partial class of the entity as these won't be seen by the EF designer when defining the association. So, is it possible to add a computed column to the mode that returns say a constant varchar 'ABC', etc and then use that column as part of the association? Many thanks, Lee.

Entity framework 4 using Guid as PK with EF4 Code First

I have this class and table: public class Foo { public Guid Id {get;set;} public string Name {get;set;} } create table Foo ( id uniqueidentifier primary KEY DEFAULT (newsequentialid()), name nvarchar(255) ) the problem is that when i try to save new foo the first one goes with the 0000-000-00 ... id and the second also, so I get constraint exception anybody knows a fix ?

Entity framework 4 Error 3004, mapping error with EF

Ok since my of my issues have been resolved,I was flying through the code, until now: I've now run into one I cant even find anything on Google for it. Here's the text of the error: Error 3004: Problem in mapping fragments starting at line 937:No mapping specified for properties StoreItem.ItemPrice in Set StoreItems. An Entity with Key (PK) will not round-trip when: Entity is type [psychoco_GodsCreationTaxidermyModel.StoreItem] F:\Projects\GodsCreationTaxi

Entity framework 4 Validation failed for one or more entities

I have following code in my asp.net MVC3 application: string msg = "Beginning report run for: "; msg += " Obligor Registry ID: " + obligorID; msg += " Requesting Organization Registry ID:" + requestingOrgID; msg += " Requesting Agent Registry ID: " + requestingAgentID; TransactionLog lg = new TransactionLog(); lg.TransactionTypeId = 2; lg.Message = msg; context.TransactionLogs.Add(lg); long

Entity framework 4 Retrieve Identity value in entity framework and still able to rollback

I want to retrieve the Identity column value after inserting a row in DB using entity framework. So I have to call context.savechanges(), but in case something goes wrong after updating row and retrieving identity column value, I want to to rollback completely. Is this possible somehow in EF 4.0.? I know how to retrieve identity column value and by rollback I mean that the inserted row should be deleted. My identity column is an autogenerated bigint type.

Entity framework 4 Dependency Injection on Multitenant Applications

I've been doing some research on DI (Unity and Ninject) for a multi-tenant ASP.Net MVC 4 application. Most articles I've read seem to refer to DI as a good tool to help provide customizations to the tenants in a multu-tenant web application. Other than that what else is it useful for within the Multitenant world. Can it help with data isolation in share db schema scenario? I'm trying to find a clean way to isolate data between customers. (I'm using tenantId in all tables where needed) (ASP.Ne

Entity framework 4 Fake IDBSet in VB.Net code conversion issue

I am having a small issue converting some C# code to VB.NET. I am working with this online blog: http://refactorthis.wordpress.com/2011/05/31/mock-faking-dbcontext-in-entity-framework-4-1-with-a-generic-repository/ In the part about creating a fake in memory IDBSet, it has the following code: System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return _data.GetEnumerator(); } IEnumerator<T> IEnumerable<T>.GetEnumerator() { return _data.GetEnumera

Entity framework 4 Why does Entity Framework not properly update OnDelete in CSDL (conceptual model)?

I recently updated a number of tables in the database to use OnDelete=Cascade, however, when I went to update my edmx file via Update model from database I noticed that the OnDelete was not properly updated. After a bit of searching, I found the following 'tip' from http://msdn.microsoft.com/en-us/library/bb738695.aspx If you update the database with the cascade delete rule and then update the existing model from the database, the Entity Framework will add the cascade delete rule t

Entity framework 4 Case Insensitive Entity Keys

I've got a view vwCountyStateJurisdiction with columns: State varchar(2) PK County varchar(20) PK Jurisdiction varchar(20) PK JurisdictionName varchar(100) (those keys are not on the view, but rather added to the entity in EF) In EF, I'm trying to add an association from the Property table, to this view. I add the referential constraint, map properties from the Property table over to the three key fields in the view, and attempt to query. The problem is, those string keys are case sensitiv

Entity framework 4 Entity Framework EDMX - Entity Pluralization Fix

We have found some bugs for certain words with the PluralizationService, for example it thinks "Campus" is plural, and it singularizes it by "Campu". Anyhow, we have figured out how to add custom mappings to the service using the ICustomPluralizationMapping interface, the problem is, how do we tell the EntityModelCodeGenerator to use our custom service instead of the base one? We are using EF 4.2 database first with custom T4 templates.

Entity framework 4 I don't understand why DbSet<>.OfType<> Throws not valid metadata type for filter operations

I have the following uninformative (in my opinion) error message: System.NotSupportedException was unhandled by user code Message='Company.Data.DataProvider.Schema.DerivedType' is not a valid metadata type for type filtering operations. Type filtering is only valid on entity types and complex types. I have the following Tables in my database: BaseType ObjectID uniqueidentifier .. other unrelated columns DerivedType ObjectID unqueidentifier UserID unqueidentifier .. other unrelated columns I

Entity framework 4 Why can't I see my entity classes in Visual Studio 2012

I am following an example in a book concerning creating entity classes from an existing database (I personally prefer Code First, but I have no choice the example is Database First!) I when I generate the classes using the designer, I get four files under the Northwind.edmx - Northwind.Content.tt, Northwind.Designer.cs, Northwind.edmx.diagram and Northwind.tt I would expect to see Northwind.Context.cs and Product.cs (in my case). These do not show up in Solution Explorer. I have looked in Expl

Entity framework 4 EDMX files created

When I created a new .edmx I got the following files under ->Model.edmx -->Model.Context.tt -->Model.Designercs -->Model.edmx.diagram -->Model.tt A previous copy of the edmx file that was created before just has the following: ->Model1.edmx --> Model1.Designer.cs Just wondering why the one I created has so many things underneath it while a previous copy has less.

Entity framework 4 Visual Studio 2010 Windows Forms Designer Problems

Isn't that a crazy error? I get this when trying to open a form containing some UserControls from another assebly and using Entity Framework and SQL CE on visual studio designer. Object of type Namespace.T[] cannot be converted to type Namespace.T[]!!! Call Stack: at System.RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo culture, Boolean needsSpecialCast) at System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr) at System.R

Entity framework 4 EntityFramework FluentAPI mapping issue

I have the following code: namespace DynamicAssembly { using System; using System.Collections.Generic; using System.Collections; using System.Data.Objects; using System.Data.EntityClient; using System.Data.Entity; using System.ComponentModel.DataAnnotations; using System.Data.Entity.ModelConfiguration; using System.Data.Entity.Infrastructure; [Table("eElementDef1")] public class ElementDef1 { public int pID { get; set; } pu

Entity framework 4 Entity framework and transcations

We are planning to develop a new application in asp.net web forms. We are using Entity Framework (with POCO classes approach). We have Presentation layer, Business logic layer and Data access layer. My question is that if on a page we want to do some transactional work, means add some data to customer,add some other data that is not relevant to customer, send an email e.t.c then how can we do it in a single transaction. Either we should start transaction on the web page's code behind? or pass

Entity framework 4 How to change connection sting of entity data model while moving application to stage?

I am an application with an EDMX file. My connection to this edmx is different in stage from the development environment. i wanted to change the connection string of edmx file while moving application to stage environment. I tried removing the edmx and creating a new edmx with the stage environment. edmx is getting created fine. But the edmx entity class is not getting referred in the code i.e it's not even showing in the intellisence. Is there a way to change the connection string directly

  1    2   3   4   5   6  ... 下一页 共 6 页