entity-framework

How to avoid trying to update a view in the Entity Framework

I have an Entity Framework project, and it imports a read-only view as one of the entities. This view is related to other entities, and when I attempt to update those entities, it tries to update the view also. I get the error: Unable to update the EntitySet 'vw_Consumer' because it has a DefiningQuery and no element exists in the ...

Why it's not a good idea to pass entities as Models in MVC?

We're developing a pretty large application with MVC 2 RC2 and we've received some feedback on the way we're using the Entity Framework's Lazy Loading. We're just getting the entities in the controller and sending them as models to the Views, that is causing that the view code asks the Database for the navigation properties we are usin...

How to refresh ObjectContext cache from db?

We are loading data from db: var somethings = Context.SomethingSet.ToList(); Then someone deletes or adds rows outside of context. Out context still has caches deleted object, because it doesn't know they were deleted. Even if I call Context.SomethingSet.ToList(), our context still contains deleted objects and navigation properties ar...

OUTER APPLY is not supported by MySQL

I am using Entity Framework with MySQL. The following query results an error: var foobar = ctx.ArticleBase.OfType<ActicleSpecial>().Include("CreatedBy.Image.Location").ToList(); Error: "OUTER APPLY is not supported by MySQL" I also get the "CROSS APPLY is not supported by MySQL" on a little different query. I have the following datam...

Entity Framework 4 and validating non-persisted objects in relation collections

Hi, What is the best practice with regard to the Entity Framework and validating new objects prior to persisting them (or in other words calling .SaveChanges()) when the new object may rely on either persisted objects or other new objects? For example, consider the following: Entity1 MyEntity1 = new Entity1(); MyEntity1.Name = "Hornbl...

Entity Framework inheritance from SQL Membership

I am using Entity Framework 3.5. I have created an object that calls "Persons" that is inherited from SQL Membership table (aspnet_Users), they are linked by UserId (Guid) with 1-to-(0..1) relationship and they both belong to "UserSet". Say, I have an existing "aspnet_User" called "jsmith" in the membership database already. How can...

Where is EntityConfiguration and ContextBuilder in Visual Studio 2010?

I see examples about code-only POCO for en entity framework 4, but I cannot find the classes EntityConfiguration and ContextBuilder and I cannot see which reference I need to add to have them. Is it part of the .Net Framework 4 or do we have to download something else? ...

Problem querying with EntityReference

When I execute the code: public List<T> GetCustomerTxList(int customerId) { var matchingPocos = new List<T>(); using (linq.AOMSEntities dataRepos = new linq.AOMSEntities()) { IEnumerable txlist = from t in dataRepos.TransactionRecord ...

Data Annotations with Entity Framework+MVC

Hi, I have a very basic entity model which I'm trying to add custom validation messages to. My metadata looks like this: namespace My.Models { [MetadataType(typeof(My.Models.ConsumerMetadata))] public partial class Consumer { } public class ConsumerMetadata { [StringLength(5)] [Required(ErrorMessage="First name is an absolu...

EF4 POCO: Snapshot vs Self-tracking over WCF

Hello Last year I developed a data access service for our project using Entity Framework (.NET3.5 of course) and using Julie Lerhman's book as a guide developed state tracking POCO objects. We use WCF and also have Silverlight 3 clients. We are moving to .NET 4.0 and I want to switch to using code generation to eliminate wasted develope...

Is there an easier way to assign relationships to new objects in Entity Framework?

In my example, I'm trying to create a new object which has references to existing objects. I'm finding myself having to retrieve complete objects from the database in order to reference them from my new object. Apologies for any small errors in the code - I'm working from memory - I don't have my code with me. My ViewModel contains th...

Entity framework - ObjectQuery return int property and assign it to variable

Hi, I need to get UserCarId(int) from this query and assign to int type variable. int UserCarId; Entities ctx = new Entities(); var query = from enq in ctx.UserCars.Include("aspnet_Users") where enq.aspnet_Users.UserId == currentUserId select enq.UserCarId ; ...

LINQ to Entities does not recognize the method ElementAt(i);

Hi, i'm using the method elementat for get a specific element of a query's result. var mds = db.TDP_MissioniDestinazioni.Where(p => p.MissioneID == missioneRow.MissioneID); destinazioneRow = mds.ElementAt(i); LINQ to Entities does not recognize the method 'TimeEntModel.TDP_MissioniDestinazioni ElementAt[TDP_MissioniDestinazioni](S...

Entity Framework Persisting local scope variable?!?!?

Hello guys I have the following method: var usuario; usuario = UniapontaService.GetUsuarioUniapontaPlanejamentoEstrategico(x => x.IdUsuario == VWUsuarioUniaponta.IdUsuario && x.PlanejamentoEstrategico.IdPlanejamentoEstrategico == HorarioTrabalhoCorrente.PlanejamentoEstrategico.IdPlanejamentoEstrategico...

Entity Framework with many-to-many deleting

I'm trying to wrap my head around Entity Framework 4. This is probably an easy question ;) I have the following entities: Article, Comment and Picture. Articles have a one-to-many association with Comments. Articles have also a many-to-many relationship with Pictures. My question is what would be the proper approach to deleting an Arti...

dropdownlistfor fill values

i have a table T with fields id, parentid, name. i make relationship with own table so parentid=>id one to many, so if parentid=null it is a parent record, and if parentid not null it is child record after mapping i have class with 2 new properties- T1 (Collection of T) and T2 (Instance of T) so how can i fill dropdownlistfor, if i not...

How to generate entity framework model from client side?

Can I generate entity framework model by clicking button in browser in client-side and save it back to web server PC? ...

Export SQL Server Database to Access using entity framework

Is it possible to export a sql server database (2008) to a new access database using the Entity framework (or anything else for that matter in code)? I have developed a desktop facing application that connects to a sql sever on a server and my client wants to be able to take snapshots of the database in access to send to people who do...

Connect to an Entity Model using Reflection

I'm writing a little utility to load Entity Data Models from an assembly and query against them. I've tried using Reflection to load a derived ObjectContext, but ObjectContext doesn't derive from MarshalByRefObject so I can't pass parameters to the constructor with Activator.CreateInstance() (according to the exception I get.) Is it ...

How do I get an instance of an asp .net mvc application's MembershipProvider from a controller?

The question title says it all. I need to get an instance of the application's MembershipProvider from within a controller. I have a custom membership implementation that has a custom User property that describes the logged in user. At the heart of the issue is that I need to retrieve this User object. My application has done a skeletal...