entity-framework

Using Entities from an Entity Framework (v3.5) Model with Fluent NHibernate

Hi all, Using Microsoft's designer for the Entity Framework (v3.5), I have created an Entity Model (*.edmx) with a generated *.Designer.cs class. I can persist my objects to MS SQL Server using the model without any problems. I am new to NHibernate, and out of curiosity, I now would like to use my model with Fluent NHibernate and SQL...

Entity Framework.. How do I map a self referencial foreign key.. eg Category has many Categories..

I have the following poco class: public class Category : IDisplayName { private ICollection<Category> children; private Category parent; public Category() { children = new List<Category>(); } public int Id { get; set; } public string Name { get; set; } public virtual Category Parent { ...

EF4 CodeFirst CTP4 - Insert with existing association

If I have an entity that has an association (e.g. Book.Publisher), how do I save a new Book and associate it with an existing Publisher? BTW I don't want to expose FK associations (i.e. PublisherId) in my model. I had been using something like this: var book = new Book { Title="whatever", Publisher = new Publisher { Id = 42 } }; cont...

Injecting changes to model data

I have certain entities that have audit trail elements like LastUpdated and LastUpdatedBy. I am looking to determine the most appropriate way to effect an update of these fields to the current date and time and current user when a model is changed. The simplest implementation would be to affect this change in my controller before I upda...

ASP.NET MVC, forms auth or custom when using EF 4?

Hello, I'm new to the ASP.NET world. Since I want to use the ORM it seems I would want an Entity to represent the User or Member or whatever, not some data tucked away by the forms authentication api. In fact I don't see how I can live without one. How do people deal with this? Roll your own authentication? Or is there a best pract...

EntityFramework - Strategies to load childs objects

I got the 2 following entity : User and Post Simple version of user : public virtual int Id { get; set; } public virtual IList<Post> Posts { get; set; } Posts aren't load by default. In certain condition, I need to load the Posts (for example, I want to count the number of posts for that user). For now, I've add a method call LoadPo...

MVC LINQ Query question

In my public ActionResult Active() { var list = _entity.CALL_UP.Where(s => s.STATE == ICallUpsState.FULLY_SIGNED) .Where(f => f.START_DATE <= DateTime.Today && f.END_DATE >= DateTime.Today) .ToList(); return View(list); } This r...

What are the advantages of EF4 or LINQ to SQL?

What are the advantages of EF4 and under what circumstances is it preferred over LINQ to SQL? ...

Questions regarding How do i tutorial (WPF/Entity Framework/ObservableCollections)

i watched How Do I: Build a WPF Data Entry Form Using Entity Framework? very confused around 15:30. when the presenter said something like when you create a LINQ query, we wont get a rich collection ... whats does she mean my "rich". the start code looks like... whats wrong with that. even if i change db.Customers.Execute(...) ...

Is it fair to use Entity Framework just as an ORM tool without even thinking of DDD or models etc?

I have a database and bunch of related tables . I just want to use EF to reduce Data-Access code for CRUD operations on those table. I dont want to change the model or anything. I am using the models as It is generated(or using POCO). Is it fair to use EF just for this(to reduce the data-access code) or it is overkill and i should think...

Generic Queries with Entity Framework

I have a Entity model that includes a large number of lookup entities. All have just ID and Name properties. I do not want to build large number of DAL classes to simply have something like: IList<Lookup1> lookup1List= ctx.Lookup1.ToList(); and another class (Or method) with IList<Lookup2> lookup2List= ctx.Lookup2.ToList(); and a...

autoincrement on table, will entity framework reflect on this before save changes?

My setup is this; first I'm defining a couple of new rows. newCompany = new company { companyInfo = value.company_info, companyName = value.company_name, organizationNumber = value.company_orgnr }; newContract = new contract { contra...

Entity Framework 4: Returning IQueryable or ObjectQuery when using LINQ to Entities?

Hi there, i have been reading when using Linq to entites a query is of type IQueryable before it is processed but when the query has been processed, it's no longer an IQueryable, but an ObjectQuery. In that case, is it correct to write methods from my layer (repository layer) to return IQueryable? Do i need to cast? Why would i want ...

How to update many-to-many related objects with Entity framework 1 & MySQL?

Hello, I have such a problem. I'm using EF1 with VS2008 SP1 & MySQL with MySQL Connector/Net 6.3.4 My database schema looks like this: CREATE TABLE IF NOT EXISTS `credential` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(50) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ; CREATE T...

Entity Framework - Using stored procedure which return same column names from different entities

I have tables named Contact and Address and both of them have "ModifiedDate" column. I have written the CUD operations using Stored procedures. However, when It came to SELECT stored procedure in which I needed to return all the contacts with their addresses, I got an error. System.Data.EntityCommandExecutionException: The data rea...

Avoiding repeated projection code in Entity Framework

I'm trying to solve a problem similar to the one described here http://stackoverflow.com/questions/1440289/initializing-strongly-typed-objects-in-linq-to-entities only from totally the opposite direction. I have a number of functions in my repository, all of which return identically shaped data. The issue is my projection code: selec...

EF4 Builder.Configurations - Unable to infer a key for entity type

Hi, I wonder if someone can help me. I'm using VS2010, .Net 4, EF4 and I'm trying to generate an objectcontext which is configured entirely in code (code-only as opposed to model-first or db-first). In short, I do: Create a ContextBuilder Configure ContextBuilder for each entity (specifying PK, FKs, Nullable, etc.) I ask the Contex...

Simulations and The Entity Framework

I'm coming from a background developing business applications so am used to MVC/n-Tier development. Most of my applications have an architecture something like this: GUI -> BL (which deals with entities) -> DAL (SQL DB) Now, I'd like to write something which is a cross between an interactive story and a simulation - There is a persis...

Is my understanding of POCO's + Entity Framework v4, correct?

Hi folks, can someone please confirm/correct me, with my understanding of using POCO's with the Entity Framework v4? If I'm going to want to use POCO's with my EF4 context, do I still need to place/create ENTITIES on the designer/.edmx ? Isn't the idea of using POCO's so I don't need to use those 'heavy' entities? or do i still need th...

Saving edited object in Entity Framework

I have object Project in my entity. I create project by: public static void Add(Project project) { var context = new Entities(); context.AddToProjects(project); context.SaveChanges(); } Next I get this object: public static Project GetProjectById(int idProject) { ...