linq-to-entities

EntityFramework LINQ Order using string and nested reflection

别等时光非礼了梦想. 提交于 2020-01-06 06:29:39
问题 I saw already some of the similar questions, but cannot find an anwser how to solve this problem. I want to have a possibility to order collection using string as property name. Model: public sealed class User : IdentityUser { #region Constructors #endregion #region Properties [Required] [Display(Name = "First name")] public string FirstName { get; set; } [Required] [Display(Name = "Last name")] public string LastName { get; set; } [ForeignKey("Superior")] public string SuperiorId { get; set;

Input string was not in a correct format (Decimal to String)

▼魔方 西西 提交于 2020-01-06 05:48:09
问题 am trying to convert a decimal to a string which I have done sucesfully in the past but for some reason its deciding not to work now. I really can't get my head around it, I have set it to decimal in SQL Management Studio and used linq to entites to pass it through but for some bizarre reason unknown to mankind it thinks am asking for a datetime. Code: protected void btnSubmit_Click(object sender, EventArgs e) { try { tblTest t = new tblTest(); t.tDecimal = Convert.ToDecimal(tbxDecimal

EF LINQ - Return entities that contain an entire collection

北城以北 提交于 2020-01-05 16:37:01
问题 I am trying to troubleshoot the following LINQ Query: public JsonResult SearchNodesByTags(string[] tags) { var nodes = _DbContext.Nodes. Where(n => n.Tags.All(t => tags.Contains(t.DisplayName))) .Select(n => new {n.NodeNativeId, n.NodeName, n.NodeClass.ClassName}) .ToList(); return Json(nodes); } The query is returning a single node that is not associated with a tag. What I want it to do, is return any nodes that have ALL the tags. 回答1: .Where(n => n.Tags.All(t => tags.Contains(t.DisplayName)

EF LINQ - Return entities that contain an entire collection

南笙酒味 提交于 2020-01-05 16:33:21
问题 I am trying to troubleshoot the following LINQ Query: public JsonResult SearchNodesByTags(string[] tags) { var nodes = _DbContext.Nodes. Where(n => n.Tags.All(t => tags.Contains(t.DisplayName))) .Select(n => new {n.NodeNativeId, n.NodeName, n.NodeClass.ClassName}) .ToList(); return Json(nodes); } The query is returning a single node that is not associated with a tag. What I want it to do, is return any nodes that have ALL the tags. 回答1: .Where(n => n.Tags.All(t => tags.Contains(t.DisplayName)

Conditional Include not working with Entityt Framework 5

我是研究僧i 提交于 2020-01-05 08:06:31
问题 I'm trying to use the Conditional Include (explained here, but it's not retrieving the child information. Why? I think I've followed all the steps... I'm using WebApi controllers and Visual Studio 2012 I've alread checked and I have doorTypes assigned to each house. It's a many to many relationship. I have this: DoorType has this property public virtual ICollection<House> Houses{ get; set; } House has this property public virtual ICollection<Door> DoorTypes{ get; set; } And I'm querying this

Conditional Include not working with Entityt Framework 5

醉酒当歌 提交于 2020-01-05 08:06:27
问题 I'm trying to use the Conditional Include (explained here, but it's not retrieving the child information. Why? I think I've followed all the steps... I'm using WebApi controllers and Visual Studio 2012 I've alread checked and I have doorTypes assigned to each house. It's a many to many relationship. I have this: DoorType has this property public virtual ICollection<House> Houses{ get; set; } House has this property public virtual ICollection<Door> DoorTypes{ get; set; } And I'm querying this

LINQ - Summing numbers stored as string

自作多情 提交于 2020-01-05 02:54:10
问题 I have the following data: PK OrderNumber USERDEFFIELD 1 0001 10 2 0001 25 3 0002 20 4 0002 22 5 0002 NULL 6 0003 ABC123 The UserDefField column is of VARCHAR type in the database. Using LINQ, how can I get the SUM(UserDefField) per order? NULL and non-numeric values for UserDefField are to be considered as zero. The result I'm trying to get: OrderNumber TotalQty 0001 35 0002 42 0003 0 If UserDefField is strictly nullable numeric field I know I would do this inside a foreach loop:

Group by hour in IQueryable

拜拜、爱过 提交于 2020-01-04 13:48:34
问题 In my project I receive some data from an SPS all x seconds. Every y minutes I archive the current Data in a database so I'm able to show statistics. The data I receive gets put in a model. Something like this but much more complex: public class Data { public DateTime ArchiveTime { get; set; } public float TempC { get; set; } public float CO2Percent { get; set; } } I have a repository for the database that returns all entries in a certain time span. See this code: // Context is my DbContext

Group by hour in IQueryable

不羁岁月 提交于 2020-01-04 13:47:08
问题 In my project I receive some data from an SPS all x seconds. Every y minutes I archive the current Data in a database so I'm able to show statistics. The data I receive gets put in a model. Something like this but much more complex: public class Data { public DateTime ArchiveTime { get; set; } public float TempC { get; set; } public float CO2Percent { get; set; } } I have a repository for the database that returns all entries in a certain time span. See this code: // Context is my DbContext

Linq to Entity Framework return a list of parents with only a subset or empty collection of children

霸气de小男生 提交于 2020-01-04 10:43:43
问题 Given a list of parents and their children I want to return a list of all parents and only their male children. This is trivial in a sql query. The problem I have is with Linq to EF I cannot seem to get the query to work in any fashion. Due to EF limitations I cannot do an include to ensure the return of the Children I want. How do I accomplish the below sql in LINQ to return my Parent Entity with Children Collection with only males or Empty collections ignoring all of the female records? SQL