entity-framework

Copying a class from DataContext causes a cached data load on next database call in Entity Framework?

Hi, I have two classes; Area and LanguageArea. I use LanguageArea to handle translated Areas. Area.cs string Title, string Description, Pictures(set of Picture class), LanguageAreas(set of LanguageArea class) LanguageArea.cs Language(defines which language area is translated in), Area, Title (translated title for the Area), Descriptio...

How to use Linq in Entity framework?

Suppose I have two table tab1, tab2. EF will create a edmx file and there are two entities created. Then I want to add a computer member to tab1, which get some result from tab2, such as count, sum. What I used is partial class: public partial class tab1{ public int Count{ get{ int cnt; //... ...

How would you use Entity Framework (1.0) with ASP.Net Membership?

I'm trying to design an entity model for an application that uses ASP.Net membership for it's user authentication. In most of the database schemas I create, records typically end up related to users via the UserId field on the aspnet_users table. That's worked fine for me in the past, but now that I'm using EF, I'm having some conceptu...

c# Entity Framework - Generics solution

Is there a generics solution for the following code? public static int SaveReorder(IList<int> listItems) { int result = 0; int order = 1; Entity1 db = null; using (ObjectContext context = new ObjectContext()) { foreach (int id in listItems) { db = Get(c...

ADO.NET Entity Data Model: Auto-generated classes.

Hi, I have a table structure like the following: Companies Addresses ********* ********* ID ID AddressID ... BillingAddressID ... AddressID and BillingAddressID are foreign keys which are present in the Addresses table. When I generate my model based on this table instead of getting w...

Building Linq Expressions with Variables

I am using Linq and the Entity Framework. I have a Page Entity, that has a many-to-many relationship to a Tag Entity. I want to create a Linq query that pulls all pages that match all of the supplied Tags (in the form of a Int64[]). I have tried various WhereIn, and BuildContainsExpression examples, but none are working as expected. ...

convert an sql query to Entity Framework

following sql query is working and gets the visits per day for the current month select date(date) as DayDate, count(*) As visitsaday from Visits group by DayDate having DayDate between date('now','start of month') and date('now','start of month','+1 month','-1 day') For days I try to figure out how to get this running with the entit...

get average Datetime from DB and subtract one Date from another

How to get an average time from an Datetime field via the Entity Framework ? How to subtract one Date from another ? I am thinking of something like: ObjectQuery<Visit> visits = myentitys.Visits; var uQuery = from visit in visits group visit by visit.ArrivalTime.Value.Day into g select ...

Insert Records into Sqlite DB using ADO.NET Entity Framework?

I'm tring to insert some records into my Sqlite database using the Entity Framework. I do not have a problem connecting to the database or mapping to the database. At least, I don't think I do. When I call "SaveChanges" an exception is fired that states: Unable to update the EntitySet 'RawReadings' because it has a DefiningQuery and ...

Can not find out the function for stored procedure in Entity Framework

Based on a database myDB, I generate edmx for all table and compile the project. Then I create stored procedure myProc in myDB. Then I update the model by "Update Model from database" in the node Stored Procedure and add myProc. It is fine. Then "Create a function import" on myProc. It is fine. Then I compiled the project, it is fine. ...

Using Microsoft Data Entity Framework with Microsoft MVC on Mono 2.4

I'm using Mono 2.4 on the Ubiquity web hosting service. I created a simple MVC tutioal applciation, linked here, and verified that it worked using all Microsoft tools. Next, the application was updated to point to a MySQL server database running on my Ubiquity host. The application works great on a Microsoft based machine. Now, I am...

Entity Framework DeleteObject child

What is the best way to delete an object (and its child objects) using EF? I'd like to pass just the id for the object to delete, and have EF handle deleting its dependent data (foreign key'd data). Do I have to retrieve the object first based on the id and then call "DeleteObject"? ...

Cast linq results to List<MyInterface>

Hi, I have extended my entities to implement specific interfaces for its type. I am trying to perform the following query: var results = from x in context.MyEntityTable where x.AProperty == AValue select x; return results.Count() > 0 ? results.Cast<IApplicationEntity>().ToList() : null; However, I kee...

entity framework entity sql vs linq to entities

what's the purpose of entity sql, i mean if you have linq to entities why would you need to write queries in string, are there any performance reasons or something ? ...

Changing the type of an (Entity Framework) entity that is part of an inheritance hierarchy

I have an inheritance hierarchy with a base Employee entity and some descendent entities for specific employee types. I need to be able to convert a base Employee entity to a more specific entity (e.g. TemporaryEmployee) and from a more specific type back to the base type (e.g. if an employee is no longer "temporary" then I want that ins...

Entity framework beta only?

Hi, I have Visual Studio Team System 2008 RTM and .NET Framework 3.5 SP1. When I try to install ADO.NET Entity Framework Tools Preview it says: ADO.NET Entity Framework Tools Preview can only be installed if at least one of the following Microsoft Visual Studio 2008 Beta 2 products is installed: Visual Basic 2008 Beta 2 Exp...

Difference between the LINQ join and sub from

Is there any difference between these two LINQ statements: var query = from a in entities.A where a.Name == "Something" from b in entities.B where a.Id == b.Id select b; var query = from a in entities.A join b in entities.B on a.Id equals b.Id w...

Adding items to a collection

Hello I have a problem adding entities to a collection. public void SaveNotificationUsergroups(int bookingobjectID, int[] NotificationUsergroups) { BookingObject bo = _entities.BookingObjectSet.Where(b => b.BookingObjectID == bookingobjectID).First(); bo.UsergroupsBookingNotifications.Load(); int _curren...

Update primary key value using entity framework

I'm trying to update one value of a compound primary key from within the entity framework and I'm getting this error: "The property 'CustomerID' is part of the object's key information and cannot be modified. " Here is my code: Dim customer As Customer = (From c In db.Customer Where c.CustomerID = "xxx" AndAlso c.SiteKey = siteKey).Fi...

EntityReference has an EntityKey property value that does not match?

I am attempting to add some entities that I have created. When I try and add the entity in question to the set (see code below) I get the following error: "The object could not be added or attached because its EntityReference has an EntityKey property value that does not match the EntityKey for this object." I can't tell what entitykey...