entity-framework

Linq to Entity Framwork 4 query counting but not returing results.

I have a query like: var fooQuery = (from x in edm.stuff where x.col == DesiredVal select x) 'stuff' is a view. When I count the results I get '1'. When I First() or FirstOrDefault() I get null. var fooCount = fooQuery.Count(); // results in 1 var fooResult = fooQuery.FirstOrDefault(); // results in null This doesn't make sense t...

Expression and Parameter

I have this method: public static Expression<Func<MyEntity, bool>> MyMethod(string someId) { return o => o.SomeProperty.Equals(someId); } This is being passed to another method that uses entity framework with this expression to retrieve the matching items. My problem is it doesn't work. If I replace the someId as part ...

Entity Framework newbie question. I select a table from the wizard, but nothing shows up.

Hi All, I create a new .edmx and the wizard allows me to choose the tables I want to expose after I pick my connection. I pick one table, and nothing shows on the design surface. The model explorer opens but nothing seems to have happened. Any ideas what's going here? There is a message on the design surface that says use the toolbox. I ...

How to get a list of EntityObject's from an EF model

I need to be able to iterate of a list of EntityObjects that are in an EF model. For Example.. foreach (System.Data.Objects.DataClasses.EntityObject eObject in ????) { } From what I can see the model context has no such public enumerator. Anyone ever done this? ...

Using a flag in an Entity Framework Where clause

I have a class (built by EF from my database) that has a field that is a flag. The field is stored in the database as an int in a column named CategoryEnum. I have an enum that specifies the permissible values of the flag: [Flags] public enum RuleCategories { None = 0x0000, ApplicantBased = 0x0001, LocationBased = 0x0002, ...

Querying using Entity Framework via Stored Procedures

I am quite frustrated with Entity Framework as most of the tutorials only show how to use it with one or two tables, and not multiple tables with relations. I was thinking of the following 'hack' to get my job done quickly: Create and Import procedures in the EF ORM to do most of the CRUD where multiple tables come into picture. What a...

How can Entity Framework queries be reused (using methods)?

I'm trying to reuse part of a query, because it's complex enough that I want to try to avoid code duplication. It seems that when calling any method inside a query, you end up with: LINQ to Entities does not recognize the method {X} method, and this method cannot be translated into a store expression What I would like to do...

ASP.net MVC2 - Customize Metadata without using Custom Attributes

I'm pretty new to MVC, I'm trying to create a model that can be localized, but it doesn't seem like that would be possible given that I have to use a custom property attribute to define displayname and validation properties. Is there a way to dynamically create the model metadata attributes (DisplayName, UIHint, etc..) as opposed to h...

Entity Framework 4

Where can I download this? I have VS2010 RTM but it does not come with it. Any ideas? ...

Update doesn't work in ADO.net Entity Data model

Hi everyone, I use ADO.net Entity Data model for work with database. In my program, I want to update a record of user table, so I use the code below to do this. In this function I send changed user info and then overwrite the information with the current user information. After I run objUser = _user; and then call objContext.SaveCha...

Linq Entity Framework generic filter method

I have some methods which perform a standard filter on data from my Entities (using Entity Framework v4). Example #1: protected IQueryable<Database.Product> GetActiveProducts( ObjectSet<Database.Product> products ) { var allowedStates = new string[] { "Active" , "Pending" }; return ( from product in products w...

Entity Framework - Saving child entities on update

Hey, I have an Invoice entity and it has child InvoiceLog entities. When I first create an Invoice and add its InvoiceLog entities and save, it works fine. However, if I then edit the Invoice and try to add additional InvoiceLog entities, it completely ignores the new InvoiceLog entities and doesn't save them at all. Any ideas what I'm ...

EF errors logging in log4net

I am trying to capture Entity Framework errors in log4net. Has anyone successfully done that? Any suggestions? ...

Self-tracking entities extension methods

When the context is generated i see there are some extension methods : AcceptChanges, MarkAsAdded, MarkAsDeleted, MarkAsModified. When should i use these methods since they are available only on the service? ...

MVC2 FormCollection options

I'm just getting started with MVC2 and going through the NerdDinner examples. I noticed that there seems to be multiple ways to pass in the form values for example: FormColelction formvalues FormCollection collection FormCollection form Why would you use one over the other and why? Does it also relate to whether you are using Entity ...

Entity Framework - Model generation Error: ''', hexadecimal value 0x1F, is an invalid character.

Hi community, my Entity Data Model designer gives an error, with the following message: "''', hexadecimal value 0x1F, is an invalid character." This error comes not from all database tables. Only one table of my database produce this error, but the very strange behavior is, the error table is not allways the same one (but always altern...

How do I write this Linq-to-Entities Query in Vb.net?

This is what my entities look like: I'm essentially trying to make a left outer join between LookupMakeModel and LookYearMakeModel for a given year. I plan on selecting a valid year from a dropdownlist and then showing a table of all the records in LookMakeModel and checking the checkbox for the LookMakeModels that have a record in L...

Silverlight + WCF RIA + Child-Parent-ReferenceBook => How to fill ComboBox on UI side correctly

Hello everyone! It could be the question about Entity Framework (WCF RIA domain model is based on it) but I'm not sure... So I have Silverlight UI (MVVM) + WCF RIA domain services + Entity Framework on server side. I have data Entities: Room -> Hotel (parent entity) <- RoomTypes plus Room has a reference to room type (so Room can be e...

Deriving 2 times on Entity Framework

Hello everybody Let's say we have tables named A, B, C . C derived from B and B derived from A. So if i want to get C table, OfType(C) will bring result as expected. But if i wrote OfType(B) result will include entries of table C. How i could get result just for B ? Is there better solution of Entity Framework ? ...

count + group by + where

I'm using Entity Framework 4 and having trouble with a query. I have two objects: Instruction Component Between these objects there's a many-to-many relation. An Instruction van point to one or more Components. And a Component can be referenced by multiple Instructions. I am trying to get how many 'finished' (status = 6) Instructions...