entity-framework

How do I delete an object from an Entity Framework model without first loading it?

I am quite sure I've seen the answer to this question somewhere, but as I couldn't find it with a couple of searches on SO or google, I ask it again anyway... In Entity Framework, the only way to delete a data object seems to be MyEntityModel ent = new MyEntityModel(); ent.DeleteObject(theObjectToDelete); ent.SaveChanges(); However,...

ObjectContext memory consumption and performance

I want to write a business object layer in a way that makes each entity object responsible for saving its own changes. I thought it would be a good way to have each entity posses its own ObjectContext, attach itself to that ObjectContext and perform the transaction whenever it needs to be saved. In LINQ to SQL, DataContext is very ligh...

Is it possible to send more than one model object to an ASP.NET MVC View?

On my start page, I'd like to display the first items from several different lists that i have on other pages - somewhat like the "recent" page here on SO displays both recent posts and recent comments. In my case I want to list the two most recent posts in a guest book, and the next upcoming event. In order to do this, how can I pass ...

Sql Server (Entity Framework): created_at , updated_at Columns

I think I should mention I'm trying to get Entity Framework\SQL server to do something that I was used to coming from Rails. I really just want to know the 'best' way to have automatic created_at & updated_at column values for records that I insert/update in the database. Right now I've hooked into the ObjectContext.SavingChanges event...

When NOT to use the Entity Framework

I have been playing around with the EF to see what it can handle. Also many articles and posts explain the various scenarios in which the EF can be used, however if miss the "con" side somehow. Now my question is, in what kind of scenarios should I stay away from the Entity Framework ? If you have some experience in this field, tell me ...

How to use ADO.net Entity Framework with an existing SqlConnection?

I have an existing asp.net website that uses an SqlConnection. I have added the ADO.net Entity Framework. I have successfully connected to the database and created the .edmx file. I am able to connect through the Entity Framework with the connectionstring that is automatically generated. I want to use the existing SqlConnection object...

Entity Framework as Repository and UnitOfWork?

I'm starting a new project and have decided to try to incorporate DDD patterns and also include Linq to Entities. When I look at the EF's ObjectContext it seems to be performing the functions of both Repository and Unit of Work patterns: Repository in the sense that the underlying data level interface is abstracted from the entity repr...

Is it Possible to Force Properties Generated by Entity Framework to implement Interfaces?

Example Interface: public Interface IEntity Property ID() as Integer end Interface I want all my EF objects to implement this interface on there Primary Keys. Is this possible? ...

Map classes to database with ado.net

Hey there, I want to know if there is way to create a database out of existing classes with the ado.net entity framework or to map existing classes to a database. I looked for tutorials and only found ways to create the classes with the entity model designer. As an example I have the class Bird with Properties Length and Age On the...

Linq-to-entities: How to create objects (new Xyz() vs CreateXyz())?

What is the best way of adding a new object in the entity framework. The designer adds all these create methods, but to me it makes more sense to call new on an object. The generated CreateCustomer method e.g. could be called like this: Customer c = context.CreateCustomer(System.Guid.NewGuid(), "Name")); context.AddToCustomer(c); wher...

Entity Framework: Loading Many to One entity

Say I have a role entity and a site entity. Now there are many roles to one site, so on the Role class there is a Site property that represents that relationship. If I wanted the roles for a site I would do this: Site.Roles.Load() Problems is, since the Site property on the Role class isn't a collection but just a single entity, the...

From LINQ to SQL to Entity Framework, what features do you want?

If you're going to be moving from LINQ to SQL to the Entity Framework what features do you most want to see move along with it? What features do you think are requirements to move existing projects? ...

C# LINQ Where Predicate Type Arguments

I have an XElement with values for mock data. I have an expression to query the xml: Expression<Func<XElement, bool>> simpleXmlFunction = b => int.Parse(b.Element("FooId").Value) == 12; used in: var simpleXml = xml.Elements("Foo").Where(simpleXmlFunction).First(); The design time error is: The type arguments for method 'Sy...

Entity Framework Dynamic Where Clause

I have a query like: var function = GetSomeExpression(); using (FooModel context = new FooModel()) { var bar = context.Bar.Where(function); } I'd like to make a generic method that can execute Where against different Entities in the context. The goal is not having to do context.Bar.Where, context.Car.Where, Context.Far.Where...

EF: Retrieving original values of modified references

I've figured out how to use the ObjectStateManager and ObjectStateEntries to determine original values of scalar properties for a given entity. What I need to know now is how to do the same for navigation properties. The GetModifiedProperties method on ObjectStateEntry doesn't return navigation properties. Any ideas? ...

How do you do full text search (FTS) with Linq to ADO.NET entity framework?

Now that SQL Server 2008 has full text search built in. I'm looking to use it to power my website's search. I'm also looking at using ADO.NET entity framework for my ORM but I was wondering how do you do full text search (FTS) with Linq to ADO.NET entity framework? Is there any support in ADO.NET entity framework or am I stuck using the...

SqlMethods.DateDiffMonth in the Entity Framework

Does anyone know what is the replacement for SqlMethods.DateDiffMonth in the Entity Framework. This is the error I am getting when I tried to use it. LINQ to Entities does not recognize the method 'Int32 DateDiffMonth(System.DateTime, System.DateTime)' method, and this method cannot be translated into a store expression. ...

C# Expression Tree Parameter for Parent Navigation Property

How can I create a ParameterExpression for the parent side of a 1 to * Navigation Property? The following works for the child entity: var parameter = Expression.Parameter( typeof(T), // where T is the entity type GetParameterName()); // helper method to get alias Trying something similar on TParent produces a query originatin...

Linq to SQL vs Entity Framework, Microsoft support for

What are the pros/cons of both? Also, I've heard various rumors concerning if Microsoft will continue to support LINQ to SQL, any further info on this would be appreciated. ...

XmlSerializer can't find EntityObject even though its referenced

Hi ... I hope that someone can help me with this problem that I've been having with XmlSerializer. I've already looked through this thread: http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/551cee76-fd80-48f8-ac6b-5c22c234fecf/ The error I am getting is: System.InvalidOperationException: Unable to generate a temporary c...