linq-to-entities

Using LINQ to Entity Framework with DB2

Is there an IBM Driver so we can use Linq to Entity framework to connect to DB2 and generate the DB2 entities on the desinger edmx file? Any links would be greatly appreciated ...

Problem with LINQ to Entities and String.StartsWith

I'm trying to build a search page using LINQ to Entities, but the following code is giving me a runtime error about l.t.e. not recognising 'Boolean StartsWith(). The code compiles just fine. How can I work around this better than shipping the StartsWith filtering out to a stored proc? return from dp in dents.DirectoryPersonEntrySe...

How to call stored procedure without error in ADO.NET Entity Framework?

How do I call a stored procedure without error in ADO.NET Entity Framework? If I use the code below, I get an error: adminNameContext.AddItemCategory(12, "ggf", DateTime.Now); Error: The data reader is incompatible with the specified 'NetTanitimTestModel.Categories'. A member of the type, 'ID', does not have a corresponding column i...

How can I avoid repeating myself in LinqToEntities?

I find myself repeating business-riles too much in my LinqToEntities when querying. That's not good. ;) Say I have two tables: Member Id Name MemberShip Id MemberId (fk to member.Id) StartDate ExpirationDate IsCancelled Now I define a valid membership as: Now is between StartDate and ExpirationDate IsCancelled i...

Linq to Sql, derived to derived association

I dont know if its possibe. I have a base table with 2 derived tables. Mammal Mammal -> Boy Mammal -> Dog A want that Dog table has a foreign key(ownerBoyId) to Boy table, but linq designer dont permit, because Boy itself dont have a Id collumn, Id is inherited. How can I resolve this problem? Associate to Base class? ...

EF Distinct (IEqualityComparer) Error

Good Morning! Given: public class FooClass { public void FooMethod() { using (var myEntity = new MyEntity) { var result = myEntity.MyDomainEntity.Where(myDomainEntity => myDomainEntity.MySpecialID > default(int)).Distinct(new FooComparer); } } } public class FooComparer : IEqualityComparer<MyEntity.My...

Entity Framework Many-To-Many + Count

I have three tables, Professors, ProfessorStudent, Student. I want all Professors + How many Students each Professor have. I can do this: context.ProfessorSet.Include("Student") context.ProfessorSet.Include("Student").ToList() will read all three tables. But i dont wanna get Student table, I want that Linq just get "Professor Table...

Linq to Entities - Increment a column using primary key

I have this code: Message message = new Message(); message.Id = 5; message.EntityKey = context.CreateEntityKey("MessageSet", entity); message.Votes++; context.Attach(entity); context.ObjectStateManager.GetObjectStateEntry(entity.EntityKey).SetModifiedProperty("Votes"); Save(); But of course, Votes initializ...

Filter child elements in an ASP.NET Linq-to-Entities

I have the following type of situation: TABLE Customers ( CustomerID int, etc... ) TABLE Orders ( OrderID int, CustomerID int, Active bit, etc... ) I am using this in an ASP.NET MVC web application using Linq-to-Entities. I want to select all Customers and populate the Customer.Orders navigational property, a...

Linq To Entities Query Oddity

I keep getting an exception about Linq to Entities not supporting certaion query expressions like this: MyDataContext db = new MyDataContext() Brand = db.Brands.First(b => b.BrandId == Int32.Parse(brandIdString)) I'm not attempting to pass along the string parsing on to the entity store, I just want to parse that string into an integ...

Modify linq query how to?

How can i shorter below codes than before? i need short and simple method: i dont want to use foreach loop because i have one value. public partial class Test : System.Web.UI.Page { StaffManagementEntities staffContext; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) ...

Should I consider LINQ to Entities?

I'm just starting with the Microsoft stack doing a web site in ASP.Net MVC and so far using LINQ to SQL. Should I consider LINQ to Entities? Does it have anything special to offer? If so, what? ...

Like Operator in Entity Framework?

We're trying to implement the "LIKE" operator in Entity Framework for our entities with string fields, but it doesn't appear to be supported. Has anyone else tried to do something like this? This blog post summarizes the issue we're having. We could use contains, but that only matches the most trivial case for LIKE. Combining contain...

How are foreign keys and Guids dealt with in LINQ to Entities?

Hi, Just using this as an example... Here are the columns in my UserProfile table: ProfileID (Primary key) UserID (Foreign key) Address PhoneNumber now, when I want to add a new user to the database using LINQ to Entities, here is what I'm doing: UserProfile profileToAdd; profileToAdd.ProfileID = 0; profileToAdd.Address =...

What would LINQ to Entities return when selecting an integer id for a given row name if the record does not exist?

Here's the code: string name = "myName"; int id = (int)_myDB.ThingTable.Where(thing => thing.ThingName == name) .Select(thing => thing.ThingId); I have an error saying System.Linq.IQueryable cannot be converted to int (I'm assuming it's so that I don't end up with a case where no rows are found- no id is returned...

LINQ to Entities to replace a join to a generated table

I have some SQL that I'm looking to replicate in LINQ to Entities. It has a table with a DateTime column and GPS location at that time for another entity in the system. It CROSS JOINS this table to the output of a table valued function which generates a "time table" over a specific period. The code for this TVF looks something like: ...

Linq To Sql Entity Operations

I'm trying to use: // this is a BreakHistory class from the ADO.NET Data Entity Model _entities _entities.AddToBreakHistory(this); _entities.SaveChanges(); and I'm getting "An entity object cannot be referenced by multiple instances of IEntityChangeTracker." error I'm thinking that my update code: _entities.ApplyPropertyChanges(this...

What happens when I'm casting an Linq to Entity query to ObjectQuery?

Hi, Simple question - what does this actually do? var oq = (ObjectQuery<TEntity>)L2EQuery; return ExecuteFirstorDefault<TEntity>(oq, MergeOption.AppendOnly); It's partly from the book Programming Entity Framework, by Julia Lerman. ...

Group by Weeks in LINQ to Entities

I have an application that allows users to enter time they spend working, and I'm trying to get some good reporting built for this which leverages LINQ to Entities. Because each TrackedTime has a TargetDate which is just the "Date" portion of a DateTime, it is relatively simple to group the times by user and date (I'm leaving out the "w...

Linq To Entities Generating Big Queries

I've been running a trace on some of the queries Linq is generating and they seem very unoptimized and clumsy. I realise you dont know my data structure but is tere anything immidiatly wrong with the following linq query IQueryable<Tasks> tl = db.Tasks .Include("Catagories") ...