entity-framework

Entity Framework: Many To Many Count and Sum

I am using the Entity Framework. I have a many to many relationship Articles <-> Categories. Each article can belong to many categories, and each category can belong to more than one article. I can get the COUNT of articles within each category: public IEnumerable<MenuCategory> GetMenuCategories() { return (from c in db.CategorySet...

Where can I get Entity Framework from?

I am sorry this is perhaps a really stupid question. Forgive me because I come from a Java background and I am making an effort to learn .Net technologies. I am trying to follow the tutorial for an ASP.Net MVC website from their website and I get to the part where I need to make a new model. When I right click they say I must choose ADO...

How Do I Use Entity Object Navigation Properties In A DropDownList On My Strongly Typed ASP.NET MVC Create and Edit Views?

I've got an Entity Data Model with Product and Family types. Each Product has one Family. I'm using this model with an ASP.NET MVC web site. I want Family DropDownLists on the Create and Edit Views of my Product controller. How Do I Use Entity Object Navigation Properties in a DropDownList on my Strongly Typed ASP.NET MVC Create and ...

How To Define The Return Type In A Function With LINQ?

I would like to know how to define a returntype in a function in following situation. I've got a products and I was returning all information or one product at a time. as you can see in my function defined below. public static Products GetProducts(int pid) { var pro = from p in context.Products select p; if(pid...

Entity Framework won't persist data in SQL Express (MDF)

Hi guyz, I'm going crazy abou this, because I can't see what I'm doing wrong!!! Please help me!!! I was developing a application using Entity Framework and storing data in a .mdf database, my code can read the data, apparently it can save too, but only apparently. I get no erros, while the program is running it act like the data was sav...

Asp.net MVC and Entity Framework, Cannot access related tables

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/SiteControl.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<Website.SimpleRepository.Page>>" %> <asp:Content ID="Content2" ContentPlaceHolderID="content" runat="server"> <h2>Page List</h2> <p> <%= Html.ActionLink("Create New", "Create") %> </p> <table> <tr...

Does the entity framework preserve ordering when it does inserts into the database?

We plan on using identity columns in our sql server database. Currently we are using guids to generate unique ids, but it turns out that the ordering is relevant so we consider switching to identity columsn. Since ordering is relevant we want to make sure that the order in which we add objects to the entity context is also the order in...

How do I update only the properties of my models that have changed in MVC?

Howdy. I'm developing a webapp that allows the editing of records. There is a possibility that two users could be working on the same screen at a time and I want to minimise the damage done, if they both click save. If User1 requests the page and then makes changes to the Address, Telephone and Contact Details, but before he clicks Sav...

Entity Framework - "Unable to create a constant value of type 'Closure type'..." error

Why do I get the error "Unable to create a constant value of type 'Closure type'. Only primitive types (for instance Int32, String and Guid) are supported in this context." when I try to enumerate the following Linq query? IEnumerable<string> searchList = GetSearchList(); using (HREntities entities = new HREntities()) { var myList = ...

How to get EF Objects to work in the WCFTestClient

I have a solution that has some EF objects. I want to pass them down to the client. When I try to test this in the WCFTestClient.exe I get this error on my objects: "This operation is not supported in the wcf test client" Is there a way to set things up so I can pass my Entity objects down to the client or am I going to have to make ...

Entity Framework - "All" method

The All method is supposed to evaluate the argument against all elements in the list. It works ok in regular Linq but when I try to use it with EF it throws an error ("Unable to create a constant value of type 'Closure type'. Only primitive types (for instance Int32, String and Guid) are supported in this context. ") Example: var myLi...

Sending an Interface definition over the wire (WCF service)

I have a WCF service that generates loads Entity Framework objects (as well as some other structs and simple classes used to lighten the load) and sends them over to a client application. I have changed 2 of the classes to implement an interface so that I can reference them in my application as a single object type. Much like this examp...

Memory consumption of EF

Good morning! Actually I'm playing around with EF atm a little bit and I need your guys help: Following scenario: I have a table with a lot of data in it. If I'm querying this table through EF, all the records get load into memory. eg. var counter = default(int); using (var myEntities = new MyEntities()) { foreach (var record in m...

What technologies to use for starting up a new project? (Technology Prespective)

Hey Guys, Today I had a nice opportunity from my manager to propose new technologies to start up a new project. Here we used to use ASP.NET and SQL mainly. I really wanna propose using ASP.NET MVC and LINQ To SQL and do some nice TDD. The question is, i don't know how to convince my manager, actually i'm not sure of these choices mysel...

How can I easily tell if two collections of .NET EntityObjects contain any of the same objects?

Pages have Roles. Users have Roles. A user may only view a page if he and it share one or more roles. This works: Dim Allow As Boolean = False CurrentPage.Roles.Load() For Each r As Role In CurrentPage.Roles r.Users.Load() For Each u As User In r.Users If u.Id = CurrentUser.Id Then Allow = True ...

Can System.Web.MVC.UpdateModel update EF Navigation Properties?

If I have 2 tables in my database: Foo and bar. Foo is identified by FooId and Bar is identifier by BarId. A Bar can have 0 to many Foos therefore Foo has BarId as a foreign key. I have a model which represents this and an view which can be used to edit a Foo and select (from a dropdown) the associated Bar. Given the following method o...

Automapper for use with Entity Framework using repository pattern?

Hi there, Been busy creating a new app, basically i have my dataccess, service layer and presentation layer... All works great but i am using the entity classes that are returned by EF. Problem here is i pass these onto the presentation layer so i need to add the entity framework reference /dataccess to the presentation layer - NOT GOOD...

Entity framework context as static

In a web application it would be ok if i declare the context of a entity framework model as static? it would be ok? its not recommended? why? Thanks! ...

javascript injection asp mvc

i have created the controller : [Authorize] [AcceptVerbs(HttpVerbs.Delete)] public ActionResult Delete(int id) { try { db.DeleteObject(db.AEROLINEA.FirstOrDefault(x => x.AEROLINEAID == id)); db.SaveChanges(); } catch { /* TODO:Display message*/ } return Vie...

How to COUNT rows within EntityFramework without loading contents?

I'm trying to determine how to count the matching rows on a table using the EntityFramework. The problem is that each row might have many megabytes of data (in a Binary field). Of course the SQL would be something like this: SELECT COUNT(*) FROM [MyTable] WHERE [fkID] = '1'; I could load all of the rows and then find the Count with:...