entity-framework-5

EF5 Code First - Changing A Column Type With Migrations

血红的双手。 提交于 2019-12-17 07:22:28
问题 I am new to EF5 Code First and I'm tinkering with a proof-of-concept before embarking on a project at work. I have initially created a model that looked something like public class Person { public int Id { get; set; } public string FirstName { get; set;} public string Surname {get;set;} public string Location {get;set;} } And I added a few records using a little MVC application I stuck on the top. Now I want to change the Location column to an enum, something like: public class Person {

Debug code-first Entity Framework migration codes

冷暖自知 提交于 2019-12-17 04:41:13
问题 I'm using Entity Framework code first in my website and I'm just wondering if there is any way to debug the migration codes. You know, like setting breakpoints and stuff like this. I'm using Package Manager Console to update the database using Update-Database . Thanks 回答1: I know that EF Code First Migrations is relatively new tool but don't forget about you are still in .NET. So you can use: if (System.Diagnostics.Debugger.IsAttached == false) { System.Diagnostics.Debugger.Launch(); } After

An object with the same key already exists in the ObjectStateManager. The ObjectStateManager cannot track multiple objects with the same key

北城以北 提交于 2019-12-17 03:22:34
问题 Using EF5 with a generic Repository Pattern and ninject for dependency injenction and running into an issue when trying to update an entity to the database utilizing stored procs with my edmx. my update in DbContextRepository.cs is: public override void Update(T entity) { if (entity == null) throw new ArgumentException("Cannot add a null entity."); var entry = _context.Entry<T>(entity); if (entry.State == EntityState.Detached) { _context.Set<T>().Attach(entity); entry.State = EntityState

How do I enable EF migrations for multiple contexts to separate databases?

谁说我不能喝 提交于 2019-12-17 02:39:12
问题 How do I enable Entity Framework 5 (version 5.0.0) migrations for multiple DB contexts in the same project, where each context corresponds to its own database? When I run Enable-Migrations in the PM console (Visual Studio 2012), there's an error because of there being multiple contexts: PM> Enable-Migrations More than one context type was found in the assembly 'DatabaseService'. To enable migrations for DatabaseService.Models.Product1DbContext, use Enable-Migrations -ContextTypeName

Why does Entity Framework with Windows Authentication not pass my credentials to SQL Server?

醉酒当歌 提交于 2019-12-14 04:10:41
问题 I'm trying to get an MVC 4 intranet site with Entity Framework 5 working on web server running IIS6 but Windows Authentication/Integrated Security is not working right because the error says Stack Trace: [SqlException (0x80131904): Login failed for user 'EASTDOMAIN\WEBDEV2$'.] System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +5104926 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +260 System.Data.SqlClient.TdsParser.Run

Query upcoming birthdays

喜夏-厌秋 提交于 2019-12-14 03:46:19
问题 I'd like to query my customers for the ones, whose birthdays are yet to come. I've tried this query, and it - of course - has failed breathtakingly: Addresses.Where(adr => adr.DateOfBirth != null && adr.DateOfBirth.Value > DateTime.Now).Take(15).ToList(); Of course this can't work properly (not if you're born in the future) and I'd like to know how I can query my Nullable<DateTime> without a year? 回答1: You can do it in one line like this: context.Addresses.Where(adr => adr.DateOfBirth != null

Ordering Column Attributes in Entity Framework

旧街凉风 提交于 2019-12-14 03:45:20
问题 I am using Entity Framework in my application,so I have mapped my property objects to database objects. The property objects have been defined using Column attribute. Now,I want to order them,but I can't find the property in Column Attribute for Order. I have included System.ComponentModel.DataAnnotations,but still not getting it Thanks in advance 回答1: just use : using System.ComponentModel.DataAnnotations.Schema; Code : [Column("Name" , Order = 1)] public int UserName { get; set; } Notice :

Automapper with linq how?

天涯浪子 提交于 2019-12-14 02:25:37
问题 Ok, I'm really struggling with finding a good example of what I need to do. So, I'll ask here. Let's say I have a entity class (EF) named Customer and a corresponding view-model class named CustomerViewModel. Using AutoMapper, I have created the following mappings: Mapper.CreateMap<CustomerViewModel, Customer>(); Mapper.CreateMap<Customer, CustomerViewModel>(); How would I modify the following code to make use of this mapping? public static List<CustomerViewModel> GetCustomers() { using (var

Customising Type Mappings in Entity Framework

隐身守侯 提交于 2019-12-14 02:18:03
问题 I'm using EF5 Code First and I'm trying to store an IPAddress object. If you try and do this directly, EF stores it as two columns, FIELDNAME_Address and FIELDNAME_Scope. Unfortunately, this is insufficient for storing IPv4 addresses, as accessing ScopeId throws an exception (see C# The attempted operation is not supported for the type of object referenced). What I'd like to be able to do is define how a type gets mapped in EF, but I'm not sure how to do that, or what the terminology for it

Entity Framework 5 - The abstract type 'X' has no mapped descendents and so cannot be mapped

≯℡__Kan透↙ 提交于 2019-12-14 01:24:41
问题 I'm getting the following error when trying to operate on this object. Anybody got any ideas? The project is on GitHub, but you will most likely not be able to run it unless you have a FIX server laying around. I can't seem to internet this error message. System.InvalidOperationException was unhandled by user code Message=The abstract type 'QuickFix.Fields.IField' has no mapped descendents and so cannot be mapped. Either remove 'QuickFix.Fields.IField' from the model or add one or more types