entity-framework-6

linq select distinct then order by a different property

柔情痞子 提交于 2019-12-13 06:07:12
问题 I have a table which contains many properties but I am focused on these. Each question has a set of answers and I need to graph each answer. The first step is to select which question then I return a list of answers. I need to select each distinct question and order it by the QOrder. <table> <tr> <td>Question</td> <td>ProjectId</td> <td>QOrder</td> </tr> <tr> <td>Q10. What is your favourite color?</td> <td>10</td> <td>1</td> </tr> <tr> <td>Q10. What is your favourite color?</td> <td>10</td>

How to call stored procedure that returns columns with spaces

女生的网名这么多〃 提交于 2019-12-13 05:51:08
问题 I'm trying to call a stored procedure using entity 6.0. After looking to these solutions here and here, they didn't solve the problem. The issue is that one of the returned columns has a spaces in it (I'm unable to change the stored procedure). I've have tried the following with no success: MyModel.cs using System; ... namespace ... { public class MyModel { [Display(Name = "ID")] public string id{ get; set; } [Display(Name = "Number Of ID")] [Column("Number Of ID")] public int number_Of_ID {

Getting error “The parameter was not bound in the specified LINQ to Entities query expression.”

*爱你&永不变心* 提交于 2019-12-13 05:50:39
问题 I am trying to create a generic way to find deals that have a date that fall within a list of user-specified date ranges. Here's my code: var closeDates = new List<Range<DateTime>> {{ new Range<DateTime>{ Start = DateTime.Now, End = DateTime.Now.AddDays(1) }}; var deals = dbContext.Deals.AsQueryable(); deals = _helperService.ApplyDateRanges(deals, deal => deal.ClosedDate, closeDates); The _helperService method: public IQueryable<T> ApplyDateRanges<T>(IQueryable<T> query, Expression<Func<T,

ASP.NET Identity Custom with Group-based Roles

别等时光非礼了梦想. 提交于 2019-12-13 05:03:07
问题 Perhaps I've misunderstood the concept of Roles in ASP.NET Identity and the database model, but I'm struggling to wrap my head around how to implement the following scenario: With ASP.NET Identity, it seems a User has permissions globally based on a Role, as opposed to permissions on a more granular level. I'm trying to implement a DB Schema in EF6 with Code-First where a User can be a member of several Groups. Instead of having a global Role however, I want the User to have one role in one

Switching between MySQL/SQL Server in EF6

余生长醉 提交于 2019-12-13 04:47:32
问题 I have a project that runs on both MySQL and SQL Server. During the last weeks I have managed to "migrate" it from plain old SQL to Entity Framework (using Spring dependency injection too) using a Database-first design based on the existing SQL Server schema. Now I need to test with MySQL. Even if I used the "appropriate" MySQL configuration, the app will crash on a ClassCastException from MySql.Data.MySqlClient.MySqlConnection to System.Data.SqlClient.SqlConnection Code: //Autowired by

Cascade delete in entity framework

◇◆丶佛笑我妖孽 提交于 2019-12-13 04:44:04
问题 I am having problems setting up relationships in entity framework 6 and making cascade deletion work. I have the following objects public class Module { public long Id { get; set; }; public virtual ICollection<Group> Groups { get; set; }; } public class Group { public long Id { get; set; }; public virtual ICollection<Field> Fields { get; set; }; } public class Field { public long Id { get; set; }; public virtual FieldLink Link { get; set; }; } public class FieldLink { public long Id { get;

Missing Id on insert of one to one-or-zero with Entity Framework

与世无争的帅哥 提交于 2019-12-13 04:43:36
问题 Using EF6 against SQL server, when saving a record with a one to zero-or-one relationship, how do the mappings need to be configured in order for the id of the "One"' to be set in the "zero-or-one" A simple case for this would be: public class Person { public int PersonId { get; set; } public string Name { get; set; } public virtual Car Car { get; set; } } public class Car { public int CarId { get; set; } public string Make { get; set; } public int? PersonId { get; set; } public virtual

Multiplicity constraint violated. The role Child_Parent_Target of the relationship Child_Parent has multiplicity 1 or 0..1

眉间皱痕 提交于 2019-12-13 04:42:49
问题 I did a lot of research but haven't found any answer that matches my problem. I even tried to use the The relationship could not be changed because one or more of the foreign-key properties is non-nullable example. No success. I'm working with Entity Framework 6 Code First (Fluent API), POCO Classes. I have a class called Parent and a class called Child One Parent can have one or more Childs (one to many relationship) So, in my ParentMapping class I did: HasMany(p => p.Childs).WithRequired(p

Use method in entity framework query

时光总嘲笑我的痴心妄想 提交于 2019-12-13 04:41:24
问题 Is there anyway around this error? I'd like to reuse the same lamba expression in other queries instead of having duplication. Can LinqKit or other linq expression do this? Error LINQ to Entities does not recognize the method 'Boolean GetEvent(Tournaments.Data.Entities.Event, System.String)' method, and this method cannot be translated into a store expression. Code public MobileEventDetailModel GetDetails(string applicationId) { var @event = (from e in _eventsRepository.DataContext.Events

Entity framework filter lambda navigation properties

别来无恙 提交于 2019-12-13 04:37:31
问题 Using .NET Entity Framework 6 I need to filter the elements of an included virtual collection. What I mean is easily explained with the following code: context.MyEntity.Include( navigationPropertyCollection => navigationPropertyCollection.Where( np => np.IsActive() ) ) the code code is just an example, to say from MyEntity I want include only active elements of navigationPropertyCollection. Is there a smart way to do it? 回答1: Note that it is not currently possible to filter which related