entity-framework

Entity Framework: insert with one-to-one reference

Hi 'overflow! I'm having a bit trouble inserting into a mssql database using Entity Framework. There's two tables that I want to insert into, where one of table 1s fields is a foreign key in table2. This is the code I have so far: Media media = null; foreach(POI p in poiList) { media = new Media() { Path = p.ImagePath...

How to update model in the database, from asp.net MVC2, using Entity Framework?

Hello. I'm building ASP.NET MVC2 application, and using Entity Framework as ORM. I am having troubles updating object in the database. Every time I try entity.SaveChanges(), EF inserts new line in the table, regardless of do I want update, or insert to be done. I tried attaching (like in this next example) object to entity, but then I g...

Can EF4 support batch updates?

Hi, Does Entity Framework v4 support batch updates/inserts so rather than sending >1 command to a db, it can send >1 command to the DB in one go? Thanks ...

Upgrading Entity Framework 1.0 to 4.0 to include foreign keys

Currently I've been working with Entity Framework 1.0 which is located under a service façade. Below is one of the save methods I've created to either update or insert the device in question. This currently works but, I can't help feel that its a bit of a hack having to set the referenced properties to null then re-attach them just t...

Return rows from stored procedure

Hello I have this code: public IEnumerable<SomeClass> GetAvalibleThingies(DateTime startDate, DateTime endDate, int categoryID) { if (_entities.Connection.State == System.Data.ConnectionState.Closed) _entities.Connection.Open(); using (EntityCommand c = new EntityCommand("SomeEntities.GetAvalibleThing...

How to update non-scalar entity properties in EF 4.0?

At first I was using this as an extension method to update my detached entities... Public Sub AttachUpdated(ByVal obj As ObjectContext, ByVal objectDetached As EntityObject) If objectDetached.EntityState = EntityState.Detached Then Dim original As Object = Nothing If obj.TryGetObjectByKey(objectDetached.EntityKey, or...

Saving my own created entites while updating in EDMX.

Hi, I have created my own entities in edmx i.e. temp table for a stored procedure. Now when i update my EDMX and adds or update any table, the entity which i created (for temp table) is removed from SSDL portion. Is there any way that my changes are not lost. Mean can extend EDMX or any other way..... Thanks... ...

EF4, self tracking, repository pattern, SQL Server 2008 AND SQL Server Compact

Hi, I am creating a project using Entity Frameworks 4 and self tracking entities. I want to be able to either get the data from a sql server 2008 database or from sql server compact database (with the switch being in the config file). I am using the repository pattern and I will have the self tracking entities sitting in a separate ass...

Entity Framework ObjectContext re-usage

I'm learning EF now and have a question regarding the ObjectContext: Should I create instance of ObjectContext for every query (function) when I access the database? Or it's better to create it once (singleton) and reuse it? Before EF I was using enterprise library data access block and created instance of dataacess for DataAccess fun...

How to have multiple projects accessing same Entity Framework project?

Ok, this question has been asked many times. Just googling with the error message: The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid. I have tried all suggestions on forums, help sites et blogs... nothing works! Stuation recap I'm splitting ...

linq null parameter

how can i do the code static string BuildMenu(List<Menu> menu, int? parentId) { foreach (var item in menu.Where(i => i.ParentMenu == parentId || i.ParentMenu.MenuId == parentId).ToList()) { } } return BuildMenu(menuList,null); so if parentId==null then return only records i =>...

WPF DataGrid duplicates new row when the newly added item is attached to the source collection.

<Page> <Page.Resources> <data:Quote x:Key="Quote"/> </Page.Resources> <tk:DataGrid DataContext="{Binding Quote}" ItemsSource="{Binding Rooms}"> <tk:DataGrid/> </Page> Code: Private Sub InitializingNewItem _ (sender As DataGrid, _ ByVal e As InitializingNewItemEventArgs) _ Handles...

ASP.NET MVC & ADO.NET Entity Framework clientside validation

Using aspnet mvc2 with the model auto-generated by entity framework: Is it possible to tell entity framework to auto-annotate all fields? eg: If database field says not null then add [Required] If DB field is a nvarchar(x) then add [StringLength(x)] And so on? What if the field name contains the string "email" eg CustomerEmail - can...

How to configure Entity Framework 4 to prevent drop when generate database

Hi, is there any option when updating classes in EF4 Modeller to disable the drop of all data and tables, just to append non existing fields and leave old tables and data untouched. I mean not to change every time on every little change to edit manual the SQL files. Thanks. ...

Entity Framework 4 Visual Studio 2008

I'm been looking around and trying to see if the Entity Framework 4 will run under Visual Studio 2008, but can;t find any references to it. Can you get EF4 working on VS2008? ...

like operator in linq

i need to use the like operator in a linq query for this: timb = time.Timbratures.Include("Anagrafica_Dipendente") .Where(p => p.Anagrafica_Dipendente.Cognome + " " + p.Anagrafica_Dipendente.Nome like "%ci%"); How can i do? ...

Parallel EntityFramework

Is it possible to make some work in parallel with entity framework for following example? using (var dbContext = new DB()) { var res = (from c in dbContext.Customers orderby c.Name select new { c.Id, c.Name, c.Role ...

SQL Server SPID and transaction scope

We are running several calls against a SQL Server database within a transaction scope using entity framework. Are we right is assuming that the SPID will be held for the duration of the transaction and that all calls will be made on the same SPID? ...

what is the default pattern in entity framework?

Hi, what is the default pattern using in entity framework? is it the Simple Entities or Change Set? Can you give me a simple code for each one? thanks ...

ADO.Net Entity Framework Custom Entity Question

Right... calling all Entity Framework experts... I have a table called Bob in my database, my EF model contains an exact mapping/definition of this. I also have a table called Jim who is also mapped to my entity model. Bob can have multiple Jim's and this relationship is enforced by foreign key constraints as it should be. So the relati...