entity-framework-4

How to Support Localization by mapping two entities to one POCO in EF 4

Hi, I've this simple Entities from DB tables But i want my POCO classes to be just two classes: public class Country { public string ID { get; set; } public string Name { get; set; } public string LocalName { get; set; } // this localized public string Region { get; set; } public IEnumerable<City> Cities { get;...

Understanding Entity Framework classes

I am working on a project where we need to fetch data from a WCF service. The service code looks up the database thru the Entity Framework. However inorder to prevent sending down EF generated classes across the wire into the proxy generated by the client we have decided to map the values from the EF classes to custom built DTO classes, ...

C#: Can I code public class MyGenericClass<T> where T:MyClass AND implement an Interface?

I see this: public class MyGenericClass<T> where T:IComparable { } and I have this: public class ProductRepository : IRepository<Product> { } How would you code something like this? public class ProductRepository<T> where T : Product : IRepository<Product> {} After all that, I thought I could simply make a single Repository clas...

OrderBy(): I need to page records, but I don't care about the order: How to specify a default KeySelector?

I need to page records but I don't know the Entity's fields. Any way to OrderBy the Key (whatever it is) or simply specify some default OrderBy Lambda? For example, I can do this with the Where Clause without knowing the Entity's properties: var myRecords = DC.Products.Where( p => p); This is a case where the Skip and Take require ...

Are there uses for TransactionScope in Entity Framework 4 in situations that do not span multiple context objects?

I am working on my first large project that uses EF4 and have been pondering concurrency situations as I am implementing certain business scenarios. I understand that EF has built in support for optimistic concurrency by setting Concurrency Mode to Fixed on entity properties. This seems to be sufficient in most cases. Several things I...

Given a Generic <E> how to create a new E and return it?

This code returns a variable set of fields and I want to return a strongly typed <E>: public IList<E> Get(Expression<Func<E, object>> selectLambda == null) { if (selectLambda == null) selectLambda = p => p; var partialSet = DC.CreateQuery<E>("[" + typeof(E).Name + "]"); foreach ( var record in partialSet) { ...

Entity Framework 4: DeleteObject(entity): Do I need to retrieve this object first?

I was deleting an Entity based on it's primary key, then I made my repository generic. Here's my current delete method: public void Del(E entity) // where E : EntityObject on the class { if( entity != null) DC.DeleteObject( entity); return; } It's running in a MVC 2 web application. So, the users send up primary key v...

Entity Framework 4: Any way to know the plural form of an Entity Type?

Given this code: private ObjectQuery<E> GetEntity() { // Pluralization concern. Table and Type need to be consistently named. // TODO: Don't get cute with database table names. XXX and XXXs for pluralization return _dc.CreateQuery<E>("[" + typeof(E).Name + "s]"); } Is there any way to determine an Entity type's plural name...

A Dictionary containing dictionaries with ObservableCollection values that have different entity types

Hi, I'm trying to implement a class in a Silverlight 4 RIA Services application that manages different ObservableCollections that are used for data binding. These ObservableCollections need to be identified by a string name and an integer classID, which I have implemented by nesting Dictionary objects in a Dictionary> object. The proble...

How to extend Entity from EF?

All entity created by EF is partial class. so it is extendable. Suppose I have entity Person like partial class Person{FirstName, LastName, .....} Then I want to add a compute property Name like: partial class Person{ [DataMember] public string Name { get { return String.Format("{0} {1}", this.FirstName, this.LastName); }...

EF4 - POCO - SaveChanges unexpectadly duplicates items in the lookup table

I'm using EF4 with POCO and the code below is what I have to update a license. I only pasted here the section of the code that is relevant to the problem, which is adding LicenseDetails. The problem is that for each LicenseDetail that are inserted, EF also unexpectadly adds rows to the "Item" lookup table. Why?! The relationship of bo...

MVC Entity Framework connection string error

What are the possible reasons for getting this error: "The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid." I am using the auto-generated connection string that the EF Wizard created and added to my app.config, so I would think it should work? ...

Entity Framework POCO generator vs Entity names

Poco generator for EF 4 is great! it took me a while to figure out how to use my existing classes as POCO's but i did and it works. One thing i can't seem to still be able to figure out, is how to use the same class for 2 entities. Seems that the POCO class has to have the same name as the Entity it is going in place of, and not ju...

EF POCO - Unable to infer a key for entity type?

I have a POCO class, mapping to a table that basically contain three primary keys as follow: public class ContactProjectSite { public int ContactID { get; set; } public int ProjectID { get; set; } public int SiteID { get; set; } public virtual Contact Contact { get; set; } public virtual Proj...

EF4 ObjectContext.EntitySet.AddObject() cascading inserts

How can I add an entity to the database through EF4 without attaching all of its referenced entities first? var entity = new MyEntity() { FK_ID = 4 }; // associated entity key using (var db = new MyEntities()) { db.MyEntity.AddObject(entity); db.SaveChanges(); db.AcceptAllChanges(); } This code keeps trying to also inser...

Remove() From Collection Does Not Mark Object As Deleted - EF4

I'm using POCO generated classes - any way that I can tweek the template so that when I remove from a child collection, the item removed is also deleted from the db ? Or maybe in the partial class I can override something, catch an event ..? Basically I want Order.OrderDetails.Remove(orderDetail) to remove the orderDetail from db. I ...

EF4 POCO, how i can filterByXX?

I am using this query: public IEnumerable.....{ var query = from d in Context.Documentos where d.CodigoEquipamento == documentoDTO.CodigoEquipamento && d.Codigo == tipoEquipamentoDTO.Codigo select new DocumentoDTO { Codigo = d.Codigo, CodigoEquipamento = d.CodigoEqu...

Stateless ORM for SOA

Hi, We need to implement a .NET WCF service that will be a part of a SOA solution, which means it's entities will pass through and be changed by both Java & .NET based services, and also on Desktop clients (though they will probably be .NET, but it shouldn't matter). In order to achieve this flexibility, all objects have to be stateles...

Entity Framework 4 vs LINQ to SQL, for small or medium-size apps, working with SQL Server

I've seen some discussion about L2S vs EF4 on Stack Overflow back in April, when VS2010 was launched, namely: Dump Linq-To-Sql now that Entity Framework 4.0 has been released? Is Entity Framework worth moving to for a new small app? Now, after 6 months, presumably people have had more interacting with EF4, so I'm curious of fresh opin...

EF4 - Add object to objectcontext without savechanges

Hi. I have a page like Order - Order lines. Order represents by some textboxes and ddls, Order lines represents by GridView. I want to let users add order lines without save changes to database. For example: he adds 4 order lines, fill order info and then hits Save button. Only an that moment all information should be saved to DB. When...