entity-framework

No connection string could be found in the application config file (But it Does Exist)

半世苍凉 提交于 2020-01-06 15:04:21
问题 I have a web API project I published to IIS and it complains there is no connection string with a specific name in my config file. I verified there is an entry in my web.config file of the web API project so it must not be picking it up. I was able to run this same web.config file locally using Visual Studio 2013. I am well aware the referenced start up project must have the connection string and that is the case for me. I verified my web API project has the connection string below (same one

Automapper, mapping to a complex object

孤者浪人 提交于 2020-01-06 14:55:45
问题 I have 2 classes i'm trying to map namely 1) Entity 2) DTO I'm trying to map Entity.Foo to DTO.Child.Foo Obviously the below will not work, how do I achieve this. I need to create a new instance of Child and then attach that to the Mapper and then set the Foo property but my AutoMapper skills are not that good! Mapper.CreateMap<Entity, DTO>() .ForMember("Child.Foo", m => m.MapFrom(entity => entity.Foo)) 回答1: Mapper.CreateMap<Entity, DTO>() .ForMember(d => d.Foo, o => o.ResolveUsing(s => new

EF 6 fluent api IsRequired attribute

青春壹個敷衍的年華 提交于 2020-01-06 14:54:52
问题 I have two classes: address and city. I want city property to be required in address class, but when I add property(p => p.City).IsRequired() to fluent api I get error that City must non-nullable value type, but when I decorate City property with [Required] annotation everything works. So how to do it with fluent api and why property(p => p.Street).IsRequired() works for string - string isn'e non-nullable value type public class Address { public int AddressId { get; private set; } public

Entity framework support for MySql unsigned decimal

孤人 提交于 2020-01-06 14:53:46
问题 Entity framework just ignores unsigned decimal column when doing db-first to generate code, since I can't change the data type of the db column to signed, any solution? 回答1: Do you need to "enforce" non-negative values? Use a TRIGGER . Or, if the values are whole numbers, then use some suitably sized INT UNSIGNED in place of DECIMAL . 来源: https://stackoverflow.com/questions/34566718/entity-framework-support-for-mysql-unsigned-decimal

ViewModel Object Convert to Entity Framework Object

若如初见. 提交于 2020-01-06 14:48:41
问题 Goal: to save ViewModel object by Entity Framework. I have UserViewModel object which has list of UnitViewModel . Then, I have a UserAdapter class which converts UserViewModel into Entity Framework User object (see Convert() below how). Now, my question is how do I convert this list of UnitViewModel to its corresponding Entity Framework Unit list? - Do I have to get each object from DB Context by calling something like context.Units.Where(u=>myListofUnitIDs.Contains(u.UnitID)) ? public class

MVC Entity Framework with Raw SQL

主宰稳场 提交于 2020-01-06 14:34:13
问题 I have the following two methods: public IEnumerable<MyModel> GetDetails() { var Results1 = GetFromSql(typeof(MyModel), "SELECT t1.field1,t2.field2,t3.field3,t4.field4 " + "FROM table1 t1 " + "INNER JOIN table2 t2 ON t1.id=t2.id " + "INNER JOIN table3 t3 ON t1.id=t3.id " + "INNER JOIN table4 t4 ON t1.id=t4.id "); var Results2 = (from t1 in context.repository.Get() join t2 in context.repository.Get() on t1.id equals t2.id join t3 in context.repository.Get() on t1.id equals t3.id join t4 in

Setting a Foreign Key Value Back to Null in Entity Framework

扶醉桌前 提交于 2020-01-06 14:21:23
问题 I have been unable to save a record to a SQL Server database when removing a foreign key value from the record. As an example, I have an existing BatchDetail record with a primary key BatchDetailID = 10. And it is associated with an existing RunDetail record that has a primary key RunDetailID = 20, and a foreign key BatchDetailID = 10. I want to disassociate the RunDetail from the BatchDetail by setting RunDetails.BatchDetailID to null. Here is the error message: A referential integrity

Setting a Foreign Key Value Back to Null in Entity Framework

时光总嘲笑我的痴心妄想 提交于 2020-01-06 14:21:14
问题 I have been unable to save a record to a SQL Server database when removing a foreign key value from the record. As an example, I have an existing BatchDetail record with a primary key BatchDetailID = 10. And it is associated with an existing RunDetail record that has a primary key RunDetailID = 20, and a foreign key BatchDetailID = 10. I want to disassociate the RunDetail from the BatchDetail by setting RunDetails.BatchDetailID to null. Here is the error message: A referential integrity

Registration method with Identity on an empty project

▼魔方 西西 提交于 2020-01-06 14:04:42
问题 I'm working in an empty MVC entity framework with ASP.NET Identity project , trying to finish a Register method for an IdentityController that handle all user related operations. The problem is that when trying to login with SignInAsync method after creating the user, the system doesn't find the references to work with that method. So, on the following code snippet...: using Microsoft.AspNet.Identity; using Microsoft.AspNet.Identity.EntityFramework; using System; using System.Collections

Referencing Non-Scalar Variables Not Supported

点点圈 提交于 2020-01-06 14:01:24
问题 hat is wrong with my query below? I'm getting a NotSupportedException ""Unable to create a constant value of type JobLanguage. Only primitive types ('such as Int32, String, and Guid') are supported in this context." public IQueryable<Candidate> GetMatchingCandidates(Job job) { return from candidate in _db.Candidates where candidate.CandidateLanguages.Any(c => job.JobLanguages.Select(jl => jl.LanguageId.Value).Contains(c.LanguageId)) orderby candidate.Name descending select candidate; } /