linq-entity-framework

Unit testing with Entity Framework

I want to test my Entities that are built using Entity Framework. My concern is that using Entity Framework means directly working with data source. So any ideas how to unit testing Entity Framework based components? ...

Multiple joins to the same table with the Entity Framework

Hi, If I have a table with two foreign key fields to another table, I.E. Table: User Field: FK_PrimaryItem_ID Field: FK_SecondaryItem_ID Table: Item Field: ItemID When I'm using the entity framework, the generated objects become: User.Item and User.Item1 and I can't differentiate between the two of them. I can map back to the n...

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 in Partial trust environment

I know that Entity Framework supports Partial trust, I personally blogged about that It was working fine, I tested it and it was fine. Now if you download the samples attached to my post about the subject, it doesn't run under default partial trust anymore!!! When I dug into System.Data.Entity assembly using reflector on the position ...

Join 3 tables in 1 LINQ-EF

I have to fill warehouse table cOrders with program using Ado.NET EF. I have SQL command but i don't know how to do this with LINQ. static void Main(string[] args) { var SPcontex = new PI_NorthwindSPEntities(); var contex = new NorthwindEntities(); dCustomers dimenzijaCustomers = new dCusto...

Entity Framework: Adding a scalar property which is equal to a FK id

Hi guys Short Question: Basically I am trying to add a scalar property to my entity which holds the ID of a FK entity. What I have tried to do thus far: What I have tried so far is adding the scalar property (called ChildId) and mapped it to the matching column in the database. Now as you can imagine I get some exceptions when I tr...

Entity Framework Stub Entities for fetches

Hi guys Alex James talks about using stub entities to stub-out/fake relationships. The context in which this is discussed is for updates/inserts/deletes. I need to be able to do the same thing for a fetch. I want to be able to fetch some objects and have the foreign key reference objects be stub entities. How could I do this. Cheers ...

Deleting Entity in Entity Model gives Foreign Key errors

Deleting Entity in Entity Model gives Foreign Key errors Error 92 Error 3013: Problem in Mapping Fragments starting at lines 5023, 5183, 5507: Missing table mapping: Foreign key constraint 'FK_TableName' from table TableName(ID) to table Other_TableName (ID): no mapping specified for the table TableName C:\MyDirector\MyModel.edmx ...

Changing an extention method from linq-to-sql to entity framework

I'm changing my project from working with Linq-to-SQL to working with Entity Framework. I have some extention methods that extend the classes created by LINQ and I'm wondering how to change them to work with the entities instead Here's an example. public static int GetPublishedArticlesCount(this Table<Article> source) { re...

Count() in Linq to Entities does not generate SELECT COUNT SQL - generates exception

I'm performing a LINQ to Entities query (.Net 3.5 SP1) as follows: ... var blah = from obj in myEntities.Objects where... select obj; return blah.Count(); When I look at the resulting SQL in the SQL profiler, the query is calling a SELECT on a result set, not a Count. From a performance perspective, this is 10x slower than doing a ha...

import Select SQL Query StoredProcedure using EntityFramework 4 in Asp.Net and C# Visual Studio 2010

I am trying to import stored-procedure using the entity framework 4 in Asp.Net,MVC and C#. But when i try to update the model into entity diagram(*.edmx) it will updated into the Entity-name.Store inside Stored-procedure folder. Stored-Procedure CREATE PROCEDURE Sp_Feedback AS BEGIN Select f.User_Id,f.Over_All_Rating,f.Features_Liked,f...

entity framework linq - which should I learn, method-based on query-based?

Just starting getting into Entity Framework and Linq for EF. I'm not sure which of the two query methods I should concentrate on, method-based or query-based? Is there an obvious choice as to which one is easier to use, for both simple and more complex queries, hence should be the one I concentrate on? Assuming I'm using VS2010 does m...

entity framework - filtering query with nullable join keys

Hi, I have a query based on the following T SQL: select t1.field1 t2.field1, t2.field2, t3.field1, t3.field2 from t1 left outer join t2 on t1.t2key = t2.id left outer join t3 on t1.t3key = t3.id In Linq to Entities the query takes the form var query = db.context.t1.include(“t2”).include(“t3”); The...

When creating database for enterprise applications, is it any useful to keep create date

I have just started with professional programming and my manager tends to dictate that i keep create, modified and delete date in all database tables that we use. I want to know does it makes sense to keep these fields for enterprise application. The reason I am asking it that because all examples, tutorials i have ever read on net, book...