linq-to-sql

Comparing non nullable `int` to `null` (LINQ)

怎甘沉沦 提交于 2021-01-27 17:06:12
问题 I have EF model class and I've decided to extend that class with one bool property: class A { public int Id { get; set; } public string Value { get; set; } } class A_DTO : A { public bool BoolProp { get; set; } } class C { public int Id { get; set; } public int A_Id { get; set; } } Then I wrote a method, which will return that A collection joined with some other C collection, which contains A <=> C mapping (well, in real world example it contains some SystemId and linq query will be joined by

Union Two Linq Queries

你。 提交于 2020-12-31 14:56:25
问题 I have two LinqToSql queries that return result sets: var grResults = (from g in ctx.GeneralRequests join rt in ctx.RequestTypes on g.RequestTypeId equals rt.RequestTypeId join sub in ctx.Logins on g.SubmitterStaffId equals sub.LoginId join onb in ctx.Logins on g.OnBehalfOfStaffId equals onb.LoginId where sub.GadId == gadId select new { Status = "Submitted", RequestId = g.GeneralRequestId, Submitter = sub.UserName, OnBehalf = (onb == null ? string.Empty : onb.UserName), RequestType = (rt ==

Update query in LINQ contains all columns in WHERE clause instead of just the primary key column

假装没事ソ 提交于 2020-12-26 10:03:37
问题 I am updating a single column in a table using Linq, take fictitious table below. MyTable (PKID, ColumnToUpdate, SomeRandomColumn) var row = (from x in DataContext.MyTable where b.PKID == 5 select x).FirstOrDefault(); row.ColumnToUpdate = 20; DataContext.SubmitChanges(); This updates the column to as expected, no surprises here. However when I inspect the SQL commands which are generated, it does this: UPDATE [dbo].[MyTable ] SET [ColumnToUpdate ] = @p2 WHERE ([PKID] = @p0) AND (

asp.net MVC Database call in partial view

邮差的信 提交于 2020-12-13 18:38:38
问题 I would like to make a database call in a partial view in asp.net MVC. I am not sure how to actually go about that. I am trying to get an instance of the repository so I can make a couple calls to the DB to build some info on the page. Not sure if I am even close but does anyone have any ideas ? <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %> <% if (Request.IsAuthenticated) { var repos = MyMVC.Models.Repository.IRepository<UserProfile>(); } %> 回答1: Try using MvcContrib.

asp.net MVC Database call in partial view

感情迁移 提交于 2020-12-13 18:34:17
问题 I would like to make a database call in a partial view in asp.net MVC. I am not sure how to actually go about that. I am trying to get an instance of the repository so I can make a couple calls to the DB to build some info on the page. Not sure if I am even close but does anyone have any ideas ? <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %> <% if (Request.IsAuthenticated) { var repos = MyMVC.Models.Repository.IRepository<UserProfile>(); } %> 回答1: Try using MvcContrib.