entity-framework

How to define a collection in a POCO in Entity Framework 4?

Lets say I've a Team class which contains 0 or more Players. The Player class is easy: public class Player { public long Id { get; set; } public string Name { get; set; } public Team Team { get; set; } } But whats the best to define the Team class? Option 1 public class Team { public long Id { get; set; } public...

What happens when you close an Entity Framework connection

We are using Entity Framework 1.0. In some cases we need to explicitly open connections, and then need to explicitly close connections. See http://msdn.microsoft.com/en-us/library/bb738582.aspx My question is, when we call "close" does the connection actually get closed, or is it just returned to the connection pool? ...

Using non primitive types in ServiceOperation for WCF Data Service (3.5SP1)

Is there any way at all to create a "mock" entity type for use in a WCF Service Operation? We have some queries we do that we need to optimize by exposing as a ServiceOperation. The problem is in order to do so we would result in a very long list of primitative types... Ex SomeoneHelpMe(int time, string name, string address, string...

How to use Transaction in Entity Framework?

How to use transactions in Entity Framework? I read some links on Stackoverflow : http://stackoverflow.com/questions/815586/entity-framework-using-transactions-or-savechangesfalse-and-acceptallchanges BUT; i have 3 table so i have 3 entities: CREATE TABLE Personel (PersonelID integer PRIMARY KEY identity not null, Ad varchar(30), S...

LINQ and SQL performance issue when working with Membership

I am using ASPNET membership with 50000 records, and we have another table called "scm_Users" which has exactly number of records, they are NOT linked by any key. I have a simple SQL: select * from dbo.aspnet_Users a, dbo.scm_Users b where a.UserName = b.UserName I can get 50000 records in less than 1 second. In LINQ, (using Entity F...

Transaction in Entity Framework refactoring and best performance

I try to use transactions in Entity Framework. I have 3 tables Personel, Prim, Finans. In Prim table you look SatisTutari (int) if i add data in SatisTutari.Text instead of int value adding float value. Transaction must be run! Everything is ok but how can I refactoring or give best performance or best writing Transaction coding! I have...

Error: “An entity object cannot be referenced by multiple instances of IEntityChangeTracker"

Hello, I'm currently using the repository pattern in an ASP.Net MVC project and have the following code: partial class Timesheet : ITimesheet { TimeSystemDBEntities _db; public Timesheet() { _db = new TimeSystemDBEntities(); } . . ...

How to model localized items

I'm currently designing a e-commerce solution. One of the primary requirements is for the store to support localized item details. The same store must be able to support multiple languages via the user's language selection and/or browser preference. I have two tables: Item (id, sku, price, ...) ItemDetails (item_id, language, ti...

Should i use viewstate to store entity objects to reduce calls across postbacks and also for tracking changes

I have generated an Entity model from database and also use the STE template to generate the entity classes. I have an entity that has 4 navigation properties and need to use this on a asp.net application. The web page is a master -detail type of a page that needs to show the main entity and also the related child entities. I have inc...

Which kinds of queries is better for querying against conceptual model in Entity Framework?

There are 3 way for querying against conceptual model in EF : LINQ to Entity Entity SQL Query Builder Methods Which one is better for which situation? Is there any performance issues for these 3 type of querying? ...

Compile error with Nested Classes

I have metadata classes nested within entity classes, as I have always done, but suddenly, when I deploy to my target web site, and try and view a page, I get e.g. the following compile error: CS0102: The type 'PvmmsModel.ActivationResource' already contains a definition for 'ActivationResourceMetadata' My code for this type looks like...

Order by descending is not working on LINQ to Entity

Order by descending is not working on LINQ to Entity In the following Query In place of ascending If I keep descending it is not working. Please help me out var hosters = from e in context.Hosters_HostingProviderDetail where e.ActiveStatusID == pendingStateId orderby e.HostingProviderName ascending select e; return host...

Is there a function similar to Math.Max for Entity Framework?

I have an entity framework query as follows; From T In Db.MyTable Where (T.Col1 - T.Col2) + T.Col3 - T.Col4 > 0 _ Select T I now need to make sure that the bracketed part '(T.Col1 - T.Col2)' does not go below zero. In .Net, I'd code it as follows (but obviously EF does not like Math.Max). From T In Db.MyTable Where Math.Max(T.Col1 -...

Resources for a quick introduction to Linq & ADO.NET Entity Framework

Hi all, I've just started working with LINQ (mainly in context of the ADO.NET Entity Framework) and currently learning the basics from The ADO.NET Entity Framework Overview @ MSDN and this LINQ tutorial. Any other online primers recommended for beginners to learn LINQ fundamentals? I generally do know the syntax and how to get the obje...

Entity Framework 4 maps DateTimeOffset to SQL datetime in Visual Studio 2010

I'm using Visual Studio 2010 RTM with .NET/Entity Framework 4 RTM with a model driven design approach. When I create an entity with a DateTimeOffset field the EF modeler tries to map the DateTimeOffset to a SQL datetime instead of a SQL datetimeoffset. I'm using SQL Server 2008 Express so the datetimeoffset is supported in the database. ...

L2E many to many query

I have four tables: Users PrivilegeGroups rdPrivileges LinkPrivilege ----------- ---------------- --------------- --------------- userId(pk) privilegeGroupId(pk) privilegeId(pk) privilegeId(pk, fk) privilegeGroupId(fk) name code priv...

Force WPF to Commit Changes on Focused Element

I'm working with VS2010, WPF and EF. I've placed controls on my window by dragging an entity out of the Data Sources toolwindow. I used the "details" setting so my entity is represented by several labels and textboxes. I've also added a button with the following code: _context.SaveChanges(); When I'm editing data, the changes in wh...

Getting timeout errors executing stored procedures with Entity Frameworks 4

I've been testing the new features in .Net 4 and have run into a strange problem. I'm calling a stored procedure in SQL 2008 that returns a query so I've added a Function Import creating a new Complex Type (called sp_Result) of the result set. When I execute it the call to the stored procedure will work intermittently on the first pass...

Manual (Dynamic) LINQ subquery using IN clause

I want to query the DB through LINQ writing manual SQL, my linq method is: var q = db.TableView.Where(sqlAfterWhere); returnValue = q.Count(); this method queries well if the value passed to variable "sqlAfterWhere" is: (this variable is String type) it.Name = 'xyz' but what if i want to use IN clause, using a sub query. (i need to...

Entity framework createquery question.

I am trying to create a generic search form to use in an EF app. I want to be ably to specify the entity to query at runtime below is a simplified version of the code. cx is the contect object, valuelists is the entity in question. 1: Dim q As String = "select c from intactentities.valuelists as c" 2: Dim x = cx.CreateQuery(Of ValueLis...