entity-framework

Handling many-to-many Entities

I work with Entity Framework and with 2 many-to-many relationship entities. I get an error on SaveChanges() when I try to associate the entities: Guid guid = new Guid(); FileLine fl = new FileLine(); guid.FileLines.Add(fl); fl...

Encoding in linq/entity framework

I'm working on a legacy where some fields uses special encodings. Is it somehow possible to set an decode the fields in the linq instead of doing as I'm doing now: XisoEncoding enc = new XisoEncoding() var q = from b in ent.Basket where b.ID == 22038 select b; Basket basket = query.First(); basket.STOMAN_MESSAG...

Save a fetched entity in diferent context.

I fetched an entity using a context.Then I made some changes to the entity and now I'd like to save the entity using a diferent context. I use the AttachTo method but i'm getting this error. An entity object cannot be referenced by multiple instances of IEntityChangeTracker. ...

Differ Domain Model From Database Schema in Entity Framework 4.0

I'm very new to the Entity Framework and trying to understand how to best architect my data layer in way that makes the most sense from the prospective of a developer. I'm working on a proof of concept using the AventureWorks database. I built a generic repository that I use to query any table in the database. Following is a short, but c...

Handling the context in Entity-framework

I have a class that provide the CRUD operation for an entity.Im using the context as private member accessible for all methods in the class. public class CustomerService { private CeoPolandEntities context; public CustomerService() { context = new CeoPolandEntities(); } public bool IsCustomerValid(str...

Using linq how do i remove multiple records from a cross reference table

Hi, My Database contains 4 tables: TABLE TBLCARTITEM (CART_ID, ITEM_ID, PROMOTION_ID, many more cart item fields) TABLE XREFCARTITEMPROMOTION (CART_ID, ITEM_ID, PROMOTION_ID) TABLE TBLPROMOTION (PROMOTION_ID, PROMOTION_TYPE_ID, many more promotion fields) TABLE TBLITEM (ITEM_ID, many more item fields) The XREFCARTIEMPROMOTION table ...

1-n relations and EntityKey with EntityFramework

Hi all. When I have an entity that holds a reference to a singular entity I can create an EntityKey and assign that value to the EntityNameReference.Value property. It works perfectly and like a charm. If I have an entity that holds a reference to multiple entities I cannot succeed in doing the same thing. Suppose an entity called Appli...

Can't call DeleteObject() on entity framework

Ok I have a console app with an app.config, and a web project with a web.config, both which have the same connection string set for my entity framework connection to my SQL Server 2008 database. My entity framwork edmx is in a class library of its own which both the console app and web project reference. In code behind in the web projec...

Silverlight to RIA Service to Business Objects Causes Build Errors

I've went through the basic tutorials associated with Silverlight and Ria Services and I am now trying to branch out to a model I have used before. I have a Silverlight project that I want to use Ria Services with. Unlike the tutorials for Ria Services that I've seen, I'm wanting to have my Domain Services to use Repository objects in ...

Setting Entity Framework Fields

I generated a Members table and a MembersType table which has a primary key which links to the Type foreign key in the Members table. The MembersType table is literally just 3 records, so that each Member can be of MemberType 1, 2 or 3. Now the problem is that when Entity Framework generates the data layer and objects for the Members ob...

Problem using OrderBy with the entity framework and ObjectContext.CreateQuery(T)

Hi, I'm having troubles using this method: public ObjectQuery<E> DoQuery(string columnName, int maximumRows, int startRowIndex) { var result = (ObjectQuery<E>)_ctx.CreateQuery<E> ("[" + typeof(E).Name + "]").OrderBy(/*???*/).Skip<E>(startRowIndex).Take(maximumRows); return result; } I'm not sure what needs to go in the ...

Does Entity Framework 4.0 allow to work without designers?

I currently enjoy working with NHibernate + Fluent NHibernate. I considered Entity Framework v1 because of its mature Linq support but I do not like working with clicky designers; and it did not support POCO, anyway. Now EF v4 does support POCOs; however, does it still require to use designers? Well, maybe I can edit those XML files but ...

Troubles creating a proper lambda expression...

This is the code I need to alter: var xParam = Expression.Parameter(typeof(E), typeof(E).Name); MemberExpression leftExpr = MemberExpression.Property(xParam, this._KeyProperty); Expression rightExpr = Expression.Constant(id); BinaryExpression binaryExpr = MemberExpression.Equal(leftExpr, rightExpr); //Create Lambda Expression for the se...

FormDataEntities en.SaveChanges() Throwing Exception

I heard about the new entity framework for .net, and decided to modify my code to use this framework, but when I try to add and delete records from the table, an Exception is thrown. I am NEW to this framework, so I can't figure out how to fix this or what is causing the exception. Here is my Code(c#): try { string key = Request.Que...

Quickly Testing Database Connectivity within the Entity Framework

[I am new to ADO.NET and the Entity Framework, so forgive me if this questions seems odd.] In my WPF application a user can switch between different databases at run time. When they do this I want to be able to do a quick check that the database is still available. What I have easily available is the ObjectContext. The test I am prefo...

Linq to entities - searching in EntityCollection navigation properties.

We have classes public Invoice: EntityObject { public EntityCollection<InvoicePosition> Positions { get {...}; set{...}; } ... } public InvoicePosition: EntityObject { public string GroupName { get {...}; set{...}; } } We are given IQueryable<Invoice>, we are not given IQueryable<InvoicePosition>. How should I find invoic...

Entity Framework - Saving Changes to Related Objects in Detached State

I'm using the Northwind database as an example for this post where I am having a problem saving detached entities back to the database using the entity framework. I have the following two methods to get me the territories and the regions: static List<Region> GetRegions() { using (NorthwindEntities entities = new Northwi...

Update ONLY some fields of attached Entity

Hello, I'm using .NET 3.5 SP1. I have entity 'AppUser': public class AppUser : System.Data.Objects.DataClasses.EntityObject{ public int Uid {get; set;} public string UserName {get; set;} public string Password {get; set;} public DateTime LastLogin {get; set;} public string Name {get; set;} public string Address ...

Entity Framework and Object Context lifetime in ASP.NET MVC

Hi there I'm using Entity Framework in my project, and I have the problem that, once I pass my entities to a View (keep in mind that these entities have lazy-initialized objects along the lines of: Products.Owner, where owner is an object that is lazily initialized) I get a run-time exception telling me that the ObjectContext is out of ...

Entity Framework: Separation of concerns

Hi there, I'm using the EF and wondering how other people are separating the Data Context from the Entities. Basically i need one tier to access the Data Context (the model object) to call SaveChanges() etc.. and other tiers need access to the Entity type itself. So for example if a method returned an Entity and i called that method fr...