entity-framework

SQL Profiler not showing inserts/deletes/updates

When I run the profiler while running my application, it only seems to show SELECTs, not INSERTs or anything that changes the database. Yet my database is being updated, so those commands must be being executed. What do I have to do to get it to show updates? (I am using Entity Framework, btw, if that might make a difference.) ...

EntityDataModel and Association table

Hi All, I have an authors -> authorsbooks <- books in my database. I created an entity data model from this and I noticed that the association entity didn't show up in the model(I think it's inferred). I want to drag 2 EntityDataSources onto the designer, a gridview of authors, and when a user clicks to select an author another gridvie...

I need to be able to separate my select statements for EF

I have about 10 calls that have the same select statement. It's more than a simple FirstOrDefault, it has some db logic inside of it. I have not seen a good way to extract this into its own method or statement. I have come close with something like this: static readonly Expression<Func<DbUser, User>> GetUser = (g) => new User { Ui...

Entity Framework Generic Repository Context

I am building an ASP.NET 4.0 MVC 2 app with a generic repository based on this blog post. I'm not sure how to deal with the lifetime of ObjectContext -- here is a typical method from my repository class: public T GetSingle<T>(Func<T, bool> predicate) where T : class { using (MyDbEntities dbEntities = new MyDbEntities()) { ...

Problem when inserting data into SQL Compact by ADO.Net Entity Framework

DatabaseEntities de = new DatabaseEntities(); Income income = de.Incomes.CreateObject(); income.Id = de.Incomes.Max(f => f.Id) + 1; income.Person = Users.SelectedValue.ToString(); income.Value = value; income.Unit = Unit.SelectedValue.ToString(); income.Descr...

Does LINQ to Entities expression with inner object context instance translated into sequence of SQL client-server requests?

I have ADO.NET EF expression like: db.Table1.Select( x => new { ..., count = db.Table2.Count(y => y.ForeignKey.ID == x.ID) }) Does I understand correctly it's translated into several SQL client-server requests and may be refactored for better performance? Thank you in advance! ...

Entity Framework 4.0: is it worthy now?

I've read a lot complains about Entity Framework in .NET 3.5 SP1, especially about its ineffectively generated SQL. Those complains had prevented me from studying Entity Framework. Now Entity Framework 4.0 has come out, which provide a lot of promises. I wonder if it's really a good ORM now, or still not yet? Is it worth to learn and us...

Entity Framework Tools for VS 2008 RTM (.net 3.5 sp1)

I'm trying to add ADO.NET Entity Data Model in my project but i can't access/find it. I found this link text but it requires VS2008 Beta 3.5 version while mine is vs2008 RTM 3.5, is there a way i could install this? ...

Datagrid selectedItem lost on window.IsEnabled = true

Hi! I have a (main)window containing a Frame. A Page is loaded to that frame, with some viewmodel as its datacontext. The View has some datagrids, where one is bound to the viewmodel and the other is bound to the selected.item (so that you get a master-details view..) the problem occurs when I display a popup box, and set the mainwin...

Calling Stored Proc using EF4 with only some of the parameters

I'm currently working on a new system that uses already existing stored procedures that are used in another system. They contain lots of logic for validation etc. so I want to use them in my new system and call them from Entity Framework 4 using WCF RIA Services. Is there a way to only supply a certain number of params as some of the S...

Print Entity Framework Model for documentation purposes?

Does anyone know how to print out an Entity Model schema? What I would like is a list of my tables (entities), along with the columns, their data type and sizes. I would to print this out to use for "reference". (I'm old school, I still prefer having stuff like this printed, versus "reading" it on a monitor.) ...

The Entity Framework takes the next data page automatically

//Bind data this.IncomeGridView.DataSource = incomeData; //If incomeData is not empty then Taking the value of the Id field of the first and the last row in data page if (incomeData.Count() > 0) { this.incomePaging_IdAtTheEndOfCurrentPage = incomeData.ToList()[incomeData.Count() - 1].Id; **this.incomePaging_IdAt...

Many to Many Relationships without Double Junction Tables, Entity Framework

I have the following setup (which works fine). Using CodeFirst (CTP4). A template has a list of influences, each influence gives a value to a trait. public class Template { public virtual int Id { get; set; } public virtual ICollection<Influence> Influences { get; set; } } public class Influence { public virtual int Id {...

Entity Framework 4 Code Genning - One Set of Entities?

Hello, I am looking to setup architecture for entity framework that will break apart the entities into multiple models. What I am wondering if it is possible to code-generate one set of entities, so that each model uses the same set of data access classes? I realize the issue with contexts, but I was wondering if each context really n...

Filtering a query in Entity Framework based upon a child value

I've got a model set up in the Entity Framework (EF) where there are two tables, parent and child, in a one to many relationship. Where I am having trouble is writing a query with linq where I am trying to retrieve a single instance of the parent while filtering upon a field in the parent and another field in the child. It would look s...

How to clear contents of ObjectContext in Entity Framework 1.0

Is there a method of manually clearing/resetting an ObjectContext back to its initial state? Note that I can't just instantiate a new context. This is using the 1.0 version of the Entity Framework. Thanks ...

Why is this Entity Framework code not saving to the database?

Hi folks, We have a simple Table per Type Entity Framework 4.0 model :- ALl classes are all POCO's. Post class is abstract. Discussion and List are classes are concretes, that inherit's from Posts (as shown in the diagram). When we try to save a Discussion, we do the following code :- Posts.AddObject(discussion); And the Sql Ser...

EF Linq - Loading Relationship Values after Where Statement Part 2

this is a second part to my first question posted here... http://stackoverflow.com/questions/3757185/linq-query-after-where-statement-not-returning-relationship-data What Im trying to do is use linq to represent this data... Get My Friends' Favorite stores, where store is an object that contains a list of the friends who also have fav...

ASP.NET MVC2 with Entity Framework 4 - AsEnumerable() or ToList() in repository?

So I've been advised a few times to disable lazy loading when building an application with the above frameworks, and that ToList() will force the queries in my repository to execute. I was told that I would avoid certain "traps" I might run into if I used AsEnumerable(). On a recent question, however, I included a bunch of ToList()s ...

Refactor LINQ to Entities query

Hi, I've implemented a search-query. It replaces special chars with "normalized" ones. I've apply this rule on different fields. Actually, the query looks very ugly and is full of DRY-violations. But refacotring this, doesn't seem to be an easy thing (for me). Of course, I just tried to refactor the whole Replace-Stuff into a separate m...