entity-framework

Entity data model, unique index

In my entity data model I have an entity with one property as the primary key and another property that will have unique values too, so I’d like to create a unique index on that other property. The situation is very similar to the Person entity with the PersonID and PersonSSN fields. Is there any way to specify in the designer or in the...

DomainService Include Get Child/Sub Entities in the client?

How do I include child entities from a DomainService, without the chance of my code being overwritten when I generate a new DomainDervice? I am trying to include sub entities with my query. For instance, I have a ParentTable and a ChildTable. I can retrieve the ChildTable entities as follows: Modify the DomainService metadata file to...

How to use join to make this queries cleaner?

I have the feeling that using joins could make this cleaner public override string[] GetRolesForUser(string username) { using (TemplateEntities ctx = new TemplateEntities()) { using (TransactionScope tran = new TransactionScope()) { int userId = (from u in ctx.Users where u.UserName == u...

Multiple Entity Framework models and the objectcontext

Hi, I have a asp.net web application that uses Entity Framework. The application data layer uses a method outlined by Jordan Van Gogh found here. In a nutshell, this method uses one shared objectcontext instance per http request and is disposed of using a AspNetObjectContextDisposalModule that inherits IHttpModule. I have added anot...

Question about Entity Framework and Transactions

public void SomeMethod1() { using (TemplateEntities ctx = new TemplateEntities()) { //do something in this ctx } } public void SomeMethod2() { using (TemplateEntities ctx = new TemplateEntities()) { //do so...

Insert Data into mulitple table using FK's using Entity framework

Hi I have tables Movie - ID, Name, Description, DirectorID-Fk, MusicID-Fk Director - ID, Name Music - ID, MusicName Now I am trying to insert a new record to movie but I dont know whether Director is already existing in the DB and same with the Music). From UI i am taking all movie information, DirectorName and MusicName. Now wh...

Do i handle well database connections (Entity Framework)?

I think i am doing something wrong in here so i will paste here so you can put me to the right track: public MembershipCreateStatus CreateUser(string username, string password, string mail, bool autoemail, string fullname) { using (TemplateEntities ctx = new TemplateEntities()) { ...

Entity Framework POCO and Self Tracking entities

Hello I wonder what's the difference between standard EF objects, POCO and Self Tracking Entities. I was looking the web but couldn't find a valuable introduction. Any help would be appreciated. ...

Modify DomainService code?

How can one modify DomainService code without the custom code being overwritten? Is there a way to put the custom code in a seperate class file? Thanks. ...

A good way to deal with date and time spans?

For my web app i need to handle access requests. Requests are entered for a monday-sunday schedule specifying hours for each day. This week schedule can repeat up to 52 times. A user can have multiple schedules during a week (mon 8-9 and mon 10-11) There are the following requirements: Searchable/filterable Detect overlapping requests ...

Entity Framework Simple Report

How would I write a query using entity framework where I need to make a list with a column for the product, category and parent category. I have not figured out how to get the parent category. Any Help is appreciated. So far I have the following: from product in Products select new { Ctg = (from prdCategory in ProductCategories ...

Am i using correctly Unit of Work here? (Entityi Framework 4 POCO)

I found some examples of how to create unit of work with ef4, i haven't used di/ioc and i would like to keep things simple and this an example (90% inspired) and i think it's ok but since i am looking at a pattern to use from now on i would like to ask an opinion one last time. public interface IUnitOfWork { void Save(); } publ...

Is the activerecord pattern built into Entity Framework 4.0?

In the past I used Sub Sonic which has the activerecord pattern baked into the framework. With Sub Sonic it was very easy to find the "dirty" fields on an update. I now have a need to create an audit table in my application that utilizes Entity Framework 4. Is there a comparable feature in EF 4 that will give me the dirty fields? Thank...

Optimizing multiple LINQ to Entity Framework queries

Hello, I have 2 Entity Framework entity sets with many-to-many relationship (compromised of 3 DB tables). For the sake of the example let's say I have a Worker entity and a Company entity, where each worker can work at multiple companies and each company can have many workers. I want to retrieve for each worker all the companies that h...

WCF Data Services and Self Tracking Entities

I have seen a couple of references stating that WCF Data Services handles change tracking automatically. Does that mean you don't need to create Self Tracking Entities (STE) and it works automatically with any entity object type? Sorry, a bit confused here and have been struggling to find a resource that clears this up for me. Thanks ...

Using Entity Framework with .NET Compact Framework 2.0 and SQL Compact 3.5

I have VS 2008 SP1 and SQL Compact Compact 3.5 SP 1 installed. I can see "ADO.NET Entity Data Model" when I go to Add -> New Item in Web Application project but same is not shown in Smart Device 2.0 application. How to use Entity Framework (which version) with .NET CF 2.0 application and SQL Compact 3.5 SP 1? ...

LINQ or Entity Framework creates unbounded SQL statement.

I work on speed optimization of my application, and what I have found is that LINQ (or EF) is creating some strange SQL for me that works slow. Here is some code : SomeList.AddRange(_databaseView .Select(l=> new SomeViewModel { Date = l.Date, ...

Code First CTP4: How to map these two entities

Let's say that I have two entities, Team and Match. In every Match, there are two teams, the HomeTeam and the AwayTeam. A Team can have many matches, but HomeTeam and AwayTeam can only have one team each. Sometimes Team is a HomeTeam, and sometimes the same Team is an AwayTeam. I have provided just the basics for each of the classes: pu...

Entity Framework: mapping tinyint to boolean

by default Entity Framework maps tinyint to byte. i tried changing the underlying type after it was generated to Boolean, but getting compilation error Member Mapping specified is not valid. The type 'Edm.Boolean[Nullable=False,DefaultValue=]' of member blah... is this possible in 4.0? it wasn't my idea to use tinyint column as b...

How to use Entity Framework 4.0 with Xml or in-memory Storage (non-SQL)

How do I specify Xml or just in-memory storge for Entity Framework models? The connection string requires a provider (usually a SQL provider string). But it won't let me omit the provider. I realize I could completely throw away the designer generated objects and go pure POCO, but then I'd have to implement my own serialization layer (c...