entity-framework

Unique IDs over database globally using Entity Framework

Hi. I want to have unique object ids over whole database. Is there any built-in feature in EF? Or may be there are some practices/patterns? thanks in advance. ...

Moving entities between contexts in .NET Entity Framework 3.5

I've got a scenario in which I want to move a bunch of object graphs between contexts. Specifically, I'm trying to import the contents of one database into another. The there is a context [CurrentContext] connected to the primary DB, and another context [ImportContext] connected to another DB. I'd like to copy the entities from Import...

If Entity Framework is meant to work with POCOs, then why the dependency on IObjectSet?

I keep hearing about EF 4.0, POCO, IObjectSet, UnitOfWork (by the way, UoW is atleast more than 17 years old when I first heard it) etc. So some folks talk about Repository "pattern". etc. There are numerous bloggers showcasing their concoction of a "wrapper" or repository or something similar. But they all require IObjectSets (or in so...

Code First Entity Configuration ToTable Problem

If I specify ToTable in the OnModelCreating override like so: protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<Team>() .MapSingleType() .ToTable("my_teams"); } it creates dbo.my_teams, however if I separate it out into classes like so: public class TeamMap : EntityConfiguration<Te...

Linq join where ?

Hi. I got: entity1 - ID, OwnerCode entity2 - OwnerCode, DepartmentCode Also I have some DepartmentCode Now i want get something like this(sql syntax): Select e1.ID from entity1 e1 join entity2 e2 on e1.OwnerCode = e2.OwnerCode and e2.DepartmentCode=7 via Linq I wrote: var q = from e1 in entityes1 join e2 in entit...

Error when calling SaveChanges() in entity framework 3.5 sp1

I'm getting the following error when I call the SaveChanges() method on my entity context: Culture 'en' is a neutral culture. It cannot be used in formatting and parsing and therefore cannot be set as the thread's current culture. My browser culture is set to en-us and so is my OS (tested on windows 7, vista and server 2003). using(Su...

How to access to sub properties in entity framework CTP4?

I am pretty new to entity framework, but given a simple object like this: public class Country { public string Name { get; set; } [Key] public string Code { get; set; } public bool IsPostalCodeRequired { get; set; } public ICollection<Province> Provinces { get; set; } } returned by a DbContext, the Provinces pro...

Delete an object with a many to many relationship from the entities framework?

I have two objects (class, student) in a database with a many to many relationship (using a simple junction table). I've figured out how to correctly add new objects to tables, and now I'd like to delete an object. I've been trying the following: // (a classobj with id==1 does exist) ClassObj cl = (from c in entities.ClassObjs where c....

JSON / MVC (3P1) HttpPost - not getting it to work on my EF class

In mixing and matching older tutorials with recent posts on MVC 3 Preview 1, I run into the following problem. I am trying to move to JSON-driven edits of my Fighter model (and the underlying db) instead of 'plain old' edits without JSON. I have an edit view (that uses a Shared EditorTemplate, fighter.ascx) setup for my Fighter class (w...

Relationship Mapping in EF4 code-only CTP (when using inheritance?)

Hi Everyone, I'm producing a simple composite patterned entity model using EF4 w/ the code-first CTP feature: public abstract partial class CacheEntity { [Key]public string Hash { get; set; } public string Creator { get; set; } public int EntityType { get; set; } public string Name { get; set; } public string Predec...

Entity Framework ObjectContext: Concurrency

I am trying to use an MVC application with Entity Framework and Repository pattern In this application, an end user may modify different entities data through multiple http requests during their session. (kind of wizard pages) However they do commit these modifications until a final commit button is clicked These also have the option to...

Bind to navigation properties

I warking with EF 4 in vs 2010 with asp.net application. In my page I put detailsview which connet to objectdatasource. I want to bind navigate property to text in murkup like this: '> according to this article (from o'reilly book) Using the Entity Framework in n-Tier ASP.NET Applications which write by julie lerman in section "Exam...

Persisting Data from the UI

I am doing a little testing with EF4. I have built a simple DB which contains one table: Table: Person Column: Id Column: Name I have a windows form application that contains a form with a gridview. I have the Model.edmx all setup and works correctly (tested without encapsulating the context). I have now encapsulated the context int...

detect field change EF

In EF4, i want to know if some fields has been change. how can i do that? thansk john ...

ASP.NET MVC/Entity Framework: Accessing aggregate objects through the aggregate root repository

I'm in the process of building my first web application using ASP.NET MVC 2 and the Entity Framework. I am using the repository pattern. From information I have gathered on Stack Overflow and other websites it appears that the consensus is to have one one controller per domain model object and one repository per aggregate root object. T...

Entity-Framework eagerly-load first item of a nav-property

Is there a way to make this code excute in one query with Entity-Framework? Private Sub LoadFirstPhone(vendor As Vendor) If Not vendor.ContactReference.IsLoaded Then _ vendor.ContactReference.Load(MergeOption.AppendOnly) vendor.Contact.Phones.Load(MergeOption.AppendOnly) End Sub I want two things: I want to be able...

Entity Framework. Code Generation dilemma.

Hello world! There is an issue I want to make choice of what is best code generation template. I consider only two of them POCO and default persistence aware template. In terms of clean code I would like the POCO and as handy one persistence aware template. I wounder if there are some drawbacks against each template, for instance, gen...

How do I have a method or property on the model in the server also get generated in the client?

I've got an application set up with RIA Services, Entity Framework 4, and Silverlight 4. It is set up in the standard fashion prescribed on MSDN here: Walkthrough: Creating a RIA Services Solution I've written a new method (or property) against one of the entity objects which resides on the server; I would like this method (or property...

Entity Framework and Sql 2008 always wants to recreate

After having some trouble with Entity Framework and SQL 2008 I decided to do a simple test so I created the following class. After testing it with a generated sdf I created a table with the same structure in a test database using sql 2008. public class People { [Key] int ID { get; set; } string FirstName { get; set; } st...

Suggestions for dynamic SQL Server access using C#

Hey guys, I'm looking for a good solution to make my life easier with regards to writing/reading to a SQL Server DB in a dynamic manner. I started with Entity-framework to make my life easier to begin with, but as the software become more general and config driven I'm finding that Entity becomes less and less appropriate because it reli...