entity-framework-4.1

MVC3 Music Store Tutorial Connection String issue

試著忘記壹切 提交于 2019-12-04 02:21:42
问题 I'm working my way through the MVC Music Store Tutorial and am running into an issue when I try to connect to the database using the entity framework model. I've tried a number of these walkthroughs, and I'm continuing to run into problems when I get to this part. I do not want to use SQL Compact Edition (although I've tried to install it just to get the tutorials to work). Rather, I have SQL Server Developer 2005 Edition as well as a named instance of SQL2008 Express (again, installed just

Entity Framework generation missing an entity

荒凉一梦 提交于 2019-12-04 01:54:13
I'm trying to generate my entities from my SQL database using the ADO.NET Entity Data Model item and from there using the ADO.NET DbContext Generator. When I generate my edmx from the database one of my entities seems to be missing in the designer but when I look at the code behind of the edmx I see it in code and when I generate the dbContext the entity isn't generated at all... Any advice would be greatly appreciated! If the table you are missing an entity for is a join table for a many-to-many relationship you don't get an entity class when you create a model from the database. EF

Entity Framework 4.1 RC: Code First EntityTypeConfiguration inheritance issue

戏子无情 提交于 2019-12-04 01:18:10
I am trying to use a common EntityTypeConfiguration class to configure the primary key for all of my entities, so that each derived configuration class does not repeat itself. All of my entities implement a common interface IEntity (which says that each entity must have an Id property of type int). My configuration base class looks like this: public class EntityConfiguration<TEntity> : EntityTypeConfiguration<TEntity> where TEntity : class , IEntity { public EntityConfiguration() { HasKey( e => e.Id ); Property( e => e.Id ).HasDatabaseGeneratedOption( DatabaseGeneratedOption.Identity ); } }

Why the Left Outer join?

青春壹個敷衍的年華 提交于 2019-12-04 01:17:59
weird one. (Probably not weird, at all) I have 3 objects, Employee, Rota and Department. public class Employee { public int Id { get; set; } public String Name { get; set; } public virtual Department Department { get; set; } } internal class EmployeeMapping : EntityTypeConfiguration<Employee> { public EmployeeMapping() { HasKey(a => a.Id); Property(a => a.Id).HasColumnName("UserId"); HasRequired<Department>(a => a.Department).WithOptional().Map(a => a.MapKey("DepartmentId")); } } public class Department { public int Id { get; set; } public String Name { get; set; } } internal class

Using mvc-mini-profiler

最后都变了- 提交于 2019-12-04 00:18:51
I'm trying to use the mvc-mini-profiler with EFCodeFirst I'm creating a DbProfiledConnection and passing it to the DbContext on construction as below. The application continues to work as expected by the sql is not exposed to the Profiler. public class WebContext : DbContext { static DbConnection _connection = new SqlConnection(ConfigurationManager.ConnectionStrings["WebContext"].ConnectionString); static DbConnection _profiledConnection = MvcMiniProfiler.Data.ProfiledDbConnection.Get(_connection); public WebContext() : base(_profiledConnection, true) { } oops my bad. I've modified it so that

EF-Code first complex type with a navigational property

狂风中的少年 提交于 2019-12-04 00:07:41
问题 My Model: public class Country { public int CountryId { get; set; } public string Name { get; set; } public virtual ICollection<User> Users { get; set; } } public class Location { public string Address { get; set; } public virtual int CountryId { get; set; } public virtual Country Country { get; set; } } public class User{ protected User() { Location = new Location(); } public int UserId { get; set; } public Location Location { get; set; } } When generating the database, I get: One or more

Moq testing LINQ Where queries

旧街凉风 提交于 2019-12-03 23:22:15
I'm using EF 4.1 to build a domain model. I have a Task class with a Validate(string userCode) method and in it I want to ensure the user code maps to a valid user in the database, so: public static bool Validate(string userCode) { IDbSet<User> users = db.Set<User>(); var results = from u in users where u.UserCode.Equals(userCode) select u; return results.FirstOrDefault() != null; } I can use Moq to mock IDbSet no problem. But ran into trouble with the Where call: User user = new User { UserCode = "abc" }; IList<User> list = new List<User> { user }; var users = new Mock<IDbSet<User>>(); users

MVC3 Action Filter Using Database (EF 4.1 DBContext, Ninject)

大憨熊 提交于 2019-12-03 22:44:37
问题 I'm trying to setup an 'Authorization' Filter on an Action, creating my own ActionFilterAttribute where I do a database lookup to determine if a user has access to a certain resource. On my class inheriting from ActionFilterAttribute, I have created an Injected(Ninject) property to hold the service that I am using for the database access. I have a parameterless constructor so that I can use this as an attribute on my actions. In the 'OnActionExecuting' Method, I am able to gain access to the

Many to Many mapping not working - EF 4.1 RC

妖精的绣舞 提交于 2019-12-03 21:45:54
UPDATE: After a bit more research it seems a number of my many-to-many mappings aren't working. Hmmm... I'm upgrading a data access project from EF 4.1 CTP4 to EF 4.1 RC and I'm having trouble with the new EntityTypeConfiguration<T> setup. Specifically I'm having an issue with a Many-to-Many relationship. I'm getting a Sequence contains no elements exception when I'm trying to get the .First() item. The particular exception isn't really that interesting. All it's saying is that there are no items BUT I know there should be items in the collection - so there must be an issue with my new

Cascading dropdown lists MVC3

戏子无情 提交于 2019-12-03 21:33:41
Relatively new to MVC and trying to get a cascading dropdown list working for train times. After looking at a lot of posts, people say that you should stay away from ViewBag/ViewData and instead focus on ViewModels, but I just can't seem to get my head round it, and it's driving me up the wall. Any tutorial seems to be either to complex or too easy and the whole viewModel idea just hasn't clicked with me yet. So here is my scenario: I have an admin system where staff can add individual train journeys. For each train time, I have an input form where the user can choose a Company, and from there