entity-framework

Entity Framework Multiple Table to Single Entity isnt querying both tables

Hi, I have a Article and Blog tables that I want to represent as a Content Entity. I have mapped both tables to the Content entity however when I query using a ObjectSet.Take(20) only the article table is being hit in the dbase. Am i wrong in thinking (hoping) the query should look where contentType = 1 and 2? Ta SQL query looks like ...

How to change Entity Framework schema during runtime?

How can you change the schema that is defined in the ssdl files generated by the Entity Framework at runtime? I understand that this is not support out of the box and I don't want to use any external projects (like the one suggest here). ...

Help me give Entity Framework Navigation Properties meaningful names, not User{1,2,3,4,...}

I have inherited a medium sized database that we are trying to use with Entity Framework in a MVC2 rewrite we are working on. We used the existing database to generate the data model (.edmx file) and all was good. Until I realized that I could not use the dot notation access all the fields. appointment.Employee.name // works fine app...

Custom function in Entity Framework query sometimes translates properly, sometimes doesn't

I have this function: public static IQueryable<Article> WhereArticleIsLive(this IQueryable<Article> q) { return q.Where(x => x != null && DateTime.UtcNow >= x.PublishTime && x.IsPublished && !x.IsDeleted); } And it works just fine in this query: from a in Articles.WhereArticleIsLive() where a.Id ==...

SQL - Multiplie one-to-many relationships

Is it possible somehow to do multiplie one-to-many relationships between 2 tables? Like: Table abc abcID defID message Table def defID abcID message If yes how can I then make a new abc entry with the entity framework? ...

Connecting to database in ASP.NET server control

As a follow on from this question I'm building a custom server control to be placed on a Sharepoint 2010 master page. The idea behind this is that it will display a menu that is dynamically populated from the database. As this is a server control, I'm building it in a dll but I've run into a small snag. As it has to connect to the data...

Entity Framework gives me a NullReferenceException

Hey guys, I have created a conceptual entity in my EF model called Task. Then I imported the INSERT, UPDATE, DELETE stored procedures into my model and mapped them to Task. In my client code, I have something like this: myModel.AddToTasks(new Task(...)); myModel.SaveChanges(); However, it gives me a NullReferenceException from Ens...

Why is IEntityCollection internal / How to find EntityCollection<T>.Count ?

In RIA services the EntityCollection<T> class is defined as follows : public sealed class EntityCollection<TEntity> : IEntityCollection, IEnumerable<TEntity>, IEnumerable, INotifyCollection...

EDMX Entity naming

I generated the EDMX file through Visual Studio 2010, I have two tables namely PersonalDetail and Address, In the personalDetail table, i have two fields namely officeaddress and residenceaddress. Both have the relationship with "Address", so while generating the EDMX file , i getting two entities like Address and Address1, but i want to...

Entity Framework CTP4 non-standard primary key name usage in BaseEntity

I am struggling already several days to solve my problem with primary key usage. Please, someone help me to solve this puzzle!!! I am using Entity Framework with CTP4 using Code First approach. I adopted for my project Repository pattern published by Huyrua see here. I am very exited with this patern and with CTP4 possibilities in parti...

WPF BindingListCollectionView Entity Framework Filtering

Afternoon all, I am attempting to filter a WPF Listbox control which is bound to a collection of Entity Framework objects. I am running into a problem which I cannot find much help on: Firstly I am creating a BindingListCollectionView and then set its DefaultView to my collection of entity objects db.Users. BindingListCollectionView...

ASP.NET MVC 2 Create Model using POST

I have the following model: public class Product { public int Id { get; set; } public string Name { get; set; } private int CategoryId { get; set; } public Category Category { get; set; } public string InventoryDetails { get; set; } } I have an action in my controller which is used to create a new product. My question is how to l...

Has anyone had any difficulty upgrading from Entity Framework 1 to Entity framework 4?

I'm looking at a project that has been developed and maintained with Entity Framework 1 that is relatively stable at this point. I'm wondering if people have ever migrated a project like that to EF 4 and if anyone can share any particular difficulties they may have had. I know there are a lot of benefits to look forward to but I'm tryi...

Basic/Simple Data Access Object (DAO) with Entity Framework 4.0

Hello all, I am trying to put together a simple POC for a n-layer application using EF4 in the data tier. I have looked at numerous examples on the web and it seems to be a common practice to use a DAO or a Repository as the wrapper to an ORM. My understanding that the main difference between the two is that a Repository is more generi...

EF code first - composite key

Hi, I have a legacy database which has two collumns and I want to map them as 1 ID is this possible for example public class Product { public string ProductID {get;set;} public string ShortDescription {get;set;} public string UserName {get;set;} } then my Modelbinder looks like this modelBinder.Entity<Product>(). HasKey(p=>p.P...

Entity SQL Using Imported Function

Hi I am trying to use a stored procedure as an imported function in an entity sql statement See my statement below, but this does not seem to work and I'm having a hard time finding out how imported functions are used in Entity SQL SELECT Cp.Calendar_Reference FROM Model.Calendar("CY", DATETIME'1999-01-01 00:0:00', DATETIME'2009-01-0...

EF4 + STE + High cardinality Many2Many object = performance issues??

I have a test bed that I created while evaluating EF4's Self Tracking Entity capabilites vs our current ORM tool (LLBLGen Pro). One of our usage scenarios produced significant performance differences. EF4 in general looked very promising, but this potential performance problem (and concern raised by it) make me very reluctant to sign u...

Is it possible to build an ObjectQuery<T> from an Expression created by another IQueryable<T>?

I'd like to pass around a custom IQueryable object to repository methods. Example: // a fake query to generate an expression public class MockQuery<T> : IOrderedQueryable<T> { // implement my own query provider internally } public class EFRepository : IRepository<MyType> { public IList<MyType> ExecuteQuery(IQueryable<MyType> ...

Entity framework performing an Insert, when it should be doing an Update

Hi Guys, I am having a real issue with the EF v1. I have quite a big EDMX with maybe 50 entitys mapped, but this one entity is causing me grief. The entity has mappings to other entitys with in effect are reference tables, but for some reason it is trying to do an Insert and not just update its self. Here is a fragment of my code.. usi...

EF save to Context but not to Datasource

Having a EF Context and a Testenity I want to get the following test to work. TestEntity testEntity = new TestEntity() { Name = "Hello World" }; context.TestEntities.AddObject(testEntity); // missing Code Assert.AreEqual(1, context.TestEntities.Count(), "Entity not in context!"); I know that it works with SaveChanges() but I do not w...