entity-framework

How to avoid using the same identifier for Class Names and Property Names?

Here are a few example of classes and properties sharing the same identifier: public Coordinates Coordinates { get; set; } public Country Country { get; set; } public Article Article { get; set; } public Color Color { get; set; } public Address Address { get; set; } public Category Category { get; set; } This problem occurs more frequ...

How can I use external expressions in Linq with EF4 (and LINQKit)?

I want to separate out often used expressions in linq queries. I'm using Entity Framework 4 and also LINQKit but I still don't know how I should do it the right way. Let me give you an example: Article article = dataContainer.Articles.FirstOrDefault(a => a.Id == id); IEnumerable<Comment> comments = (from c in article.Comments wher...

How to find out field maximum length in Entity Framework in .NET 4?

According to this question, there's no built-in way in EF v1 to figure out the length of a field. Is there a built-in way to do so in the Entity Framework that ships with .NET 4, if so - how? ...

Problem creating ObjectContext from different project inside solution.

I have two projects in my Solution. One implements my business logic and has defined entity model of entity framework. When I want to work with classes defined within this project from another project I have some problems in runtime. Actually, the most concerning thing is why I can not instantiate my, so called, TicketEntities(ObjectCont...

Entity Data Model & DataGridView - Creating new objects

I'm pretty new to the EDM, so bear with me. I have a windows form that has a DataGridView on it that's bound from the EDM I created. I figured out how to update my changes fine, but it's when the user creates a new row that I'm having a problem. I tried numerous ways and many google searches, but came up with nothing so far. Here's h...

How does Entity Framework 4.0 determine which parameters are required for the factory method of an entity ?

Hi, I am working with Entity Framework 4.0 (VS 2010 Beta 2, NOT RC). I can model the EDM and produce the required database. When I ask VS to generate the code for the model, it generates the expected .designer.cs file. When I look at the factory methods for each entity that the designer has generated, I've noticed that it doesn't inc...

How to fix type names conflicts in Dynamic Data

Hi Guys! We're working in a Dynamic Data project that will handle entities coming from two different namespaces: myModel.Abby and myModel.Ben. whose classes are: Abby myModel.Abby.Car myModel.Abby.Lollipop Ben myModel.Ben.Car myModel.Ben.Apple So myModel.Abby.Car and myModel.Ben.Car are homonym. when I try to register bo...

How to implement a left outer join in the Entity Framework.

I have the following SQL query:- select distinct * from dbo.Profiles profiles left join ProfileSettings pSet on pSet.ProfileKey = profiles.ProfileKey left join PlatformIdentities pId on pId.ProfileKey = profiles.Profilekey I need to convert it to a LinqToEntities expression. I have tried the following:- from profiles in _dbContext....

MVC 2 Entity Framework View Model Insert

This is driving me crazy. Hopefully my question makes sense... I'm using MVC 2 and Entity Framework 1 and am trying to insert a new record with two navigation properties. I have a SQL table, Categories, that has a lookup table CategoryTypes and another self-referencing lookup CategoryParent. EF makes two nav properties on my Category...

Entity Framework cascading delete problems - Foreign key set to null

Hello, I have the following Model which I mapped with the Entity Framework: Mitglied -> Auftrag -> Teilprojekt I have set up everything in the database with foreign keys and "on delete cascade". If I perform some tests on the database everything works fine. The problem arises as soon as I use the Entity Framework to add and especially d...

SqlBulkCopy and Entity Framework

My current project consists of 3 standard layers: data, business, and presentation. I would like to use data entities for all my data access needs. Part of the functionality of the app will that it will need to copy all data within a flat file into a database. The file is not so big so I can use SqlBulkCopy. I have found several arti...

adding validation annotators to model classes when using Linq-to-SQL

How should I add the following attrubute [Required(ErrorMessage="...")] to one of the model properties when my model classes are automatically generated. There is a solution here, but it seems to be working only on Entity Framework ...

EF 4: Removing child object from collection does not delete it - why?

I use Entity Framework 4 and I have parent - child relation with "Cascade Delete" set. So i would expect when i remove a child from the parent that the child is deleted when i call SaveChanges(). cuRepository.Attach(_controlUnit); foreach (var recipe in recipes) { _controlUnit.Recipes.Remove(recipe); ...

How would one code an entity instance method to persist itself in Entity Framework 4.0 ?

Hi, I'm working with a small model in Entity Framework 4.0. I'd like to have an instance method of the object that represents an entity persist the entity to the database. So instead of from "external" code: public static void Main(string[] args) { using (EFContext ctx = new EFContext()) { context.AnEntitySet.AddObject(r...

ASP.NET EnqityDataSource WhereParameters, creates new property.

I am trying to populate GridView, using EntityDataSource(code behind), I need to able to sort GridView. However when I sort i get error: A property with name 'aspnet_Users.UserId1' does not exist in metadata for entity type So I beleive it is because I generate where parameter in code behind: ActiveEnqDataSource.WhereParameters.Add(new...

How do I upgrade an existing EDMX 1.0 model to the new EDMX 2.0?

I'd like to upgrade an existing EDMX model without having to regenerate it by hand. The database is old, contains virtually no foreign keys and has many tables that had to be merged into single entities. I would like to use the EDMX 2.0 that comes with Visual Studio 2010, but I do not want to recreate the model by hand as that would put ...

UDF call in entity framework is cached

I am doing a test after reading an article http://blogs.msdn.com/alexj/archive/2009/08/07/tip-30-how-to-use-a-custom-store-function.aspx about udf function called. When I use a function with objectContext.Entities.Where( t=> udf(para1, para2) == 1), here the Entities is not ObjectQuery, but an ObjectSet, the first time I call the method...

Get correct output from UTF-8 stored in VarChar using Entity Framework or Linq2SQL?

Borland StarTeam seems to store its data as UTF-8 encoded data in VarChar fields. I have an ASP.NET MVC site that returns some custom HTML reports using the StarTeam database, and I would like to find a better solution for getting the correct data, for a rewrite with MVC2. I tried a few things with Encoding GetBytes and GetString, but I...

How to load entities into private collections using the entity framework

I have a POCO domain model which is wired up to the entity framework using the new ObjectContext class. public class Product { private ICollection<Photo> _photos; public Product() { _photos = new Collection<Photo>(); } public int Id { get; set; } public string Na...

Converting a Linq expression tree that relies on SqlMethods.Like() for use with the Entity Framework

I recently switched from using Linq to Sql to the Entity Framework. One of the things that I've been really struggling with is getting a general purpose IQueryable extension method that was built for Linq to Sql to work with the Entity Framework. This extension method has a dependency on the Like() method of SqlMethods, which is Linq to...