entity-framework-4

Using Entity Framework navigation properties without creating lots of queries (avoiding N+1)

╄→尐↘猪︶ㄣ 提交于 2019-12-19 10:18:41
问题 I've been using Entity Framework Profiler to test my data access in an MVC project and have come accross several pages where I'm making far more db queries than I need to because of N+1 problems. Here is a simple example to show my problem: var club = this.ActiveClub; // ActiveClub uses code similar to context.Clubs.First() var members = club.Members.ToList(); return View("MembersWithAddress", members); The view loops through Members and then follows a navigion property on each member to also

WCF ria service SP1 timeout expired

怎甘沉沦 提交于 2019-12-19 10:15:49
问题 My solution is Silverlight which uses WCF RIA service SP1 and Entity Framework 4. I have a problem with loading large size data. I've got this error message. System.ServiceModel.DomainServices.Client.DomainException : Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. I think that it's a problem regards with timeout, so I tried below code. It worked when I hadn't install WCF Ria service "SP1". But it's not working since I've

DataBinding to Calculated Field

限于喜欢 提交于 2019-12-19 09:14:28
问题 I'm running into a small problem where I'm trying to bind a DataTextColumn of a DataGrid to a Calculated Field. WPF <DataGrid ItemsSource="{Binding Path=CurrentRoster, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" AutoGenerateColumns="False" AlternatingRowBackground="Gainsboro" AlternationCount="2"> <DataGrid.Columns> <DataGridComboBoxColumn Header="Student Enrolled" ItemsSource="{Binding Source={StaticResource AvailableStudents}}" SelectedItemBinding="{Binding Path=Student}"> <

How can i update app.config connectionstring Datasource value in C#?

喜夏-厌秋 提交于 2019-12-19 08:57:34
问题 Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); config.ConnectionStrings.ConnectionStrings["MyConnectionString",String.Format("DataSource={0};")].ConnectionString=textBox1.Text; config.Save(ConfigurationSaveMode.Modified, true); ConfigurationManager.RefreshSection("connectionStrings"); I'm having trouble at line two. I cant seem to get the syntax correct. As you can see, i only want to update the DataSource value only. For example, if current

InsertOnSubmit equivalent in DbContext.DbSet using Entity Framework 4 code first

陌路散爱 提交于 2019-12-19 06:08:31
问题 I am using entity framework code first approach, and I am building a generic Repository class that provides data access. In this class I want an Add(T entity) method. However, there is no InsertOnSubmit method as part of the DbSet<T> class, and if I try to use the Add method, I get a compile time error: The type 'TEntity' must be a reference type in order to use it as parameter 'TEntity' in the generic type or method 'System.Data.Entity.DbContext.Set<TEntity>()' This is the method: public

Why doesn't EF 4 generate association for FK relation to column with unique index?

前提是你 提交于 2019-12-19 05:50:12
问题 I have run into a scenario where Entity Framework 4.0 does not generate an association to an entity backed by a table having a unique index, and I am wondering why. The basic setup is this: Let's say I have two tables in SQL Server 2008 R2 and a foreign key relation: CREATE TABLE [dbo].[User]( [Id] [int] IDENTITY(1,1) NOT NULL, [GroupId] [int] NULL, CONSTRAINT [PK_User] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS

Should i use Pooling=False in Entity Framework Connection String?

旧时模样 提交于 2019-12-19 04:14:38
问题 We have an ASP.Net MVC3 application that is running on Azure, connecting to a Sql Azure Database via Entity Framework. The Developer that produced this has Pooling=False in the connection string. I would have thought this was a bad idea - wouldn't we want to re-use the connections if possible? Can anyone give me some guidance of when this might be a good idea? Thanks! 回答1: Yes, it is bad idea to have pooling=False. I don't use this option even for development. You should always use the SQL

Implementing repository for EF4 using DDD and IoC

这一生的挚爱 提交于 2019-12-19 03:24:07
问题 I think I'm going in circles. I'm working on an MVC 3 solution using EF4 & POCOs (database-first) and IoC. My repository and UoW patterns were mostly adopted from this article and this article. My solution is made up of the following projects: Implementations: Presentation (MVC site) Domain Services (business layer) Domain Repository (data access) Domain Context (my EF4 edmx and generated context) Domain Models (my EF4 generated POCOs) Interfaces: Domain Services Interfaces (business layer

Removing all records from navigation properties in Entity Framework

坚强是说给别人听的谎言 提交于 2019-12-19 03:23:11
问题 I have 1:N relationship between Program and Student tables which EF converted into navigation property. Now I want to delete all those records in this navigation students. I started like this: foreach(Student student in program.Students) program.Students.Remove(student); But I am a little bit skeptical about this. Than I tried this way: while (program.Students.Count > 0) program.Students.Remove(program.Students.ToList()[0]); But this seems weird too. Is there some simpler way to do this or if

Entity framework generates values for NOT NULL columns which has default defined in db

独自空忆成欢 提交于 2019-12-19 03:01:23
问题 Hi I have a table Customer. One of the columns in table is DateCreated . This column is NOT NULL but default values is defined for this column in db. When I add new Customer using EF4 from my code. var customer = new Customer(); customer.CustomerName = "Hello"; customer.Email = "hello@ello.com"; // Watch out commented out. //customer.DateCreated = DateTime.Now; context.AddToCustomers(customer); context.SaveChanges(); Above code generates following query. exec sp_executesql N'insert [dbo].