How to convert this SQL statement to linq in C #?

Please help me to convert this SQL statement to Linq in C#: string cmd = "SELECT * FROM dbo.Personnel WHERE (dbo.Personnel.FName LIKE @FName + '%' AND dbo.Personnel.LName LIKE @LName +'%')"; if (objPPersonnel.PersonnelCode != 0) { cmd += "A

C # Same dates, 2 tick values

I'm creating a CRUD with and Entity Framework. When I try get LastModification DateTime for same User, I get two differents values. I don't know why I get two differents values for same Datetime.There is a difference of milliseconds in both d

Entity to model the mapping in LINQ

I have article and author classes. Fetch articles like so and map entity to model: public List<Model.Article> GetArticleList() { using (var db = new ArticlesContext()) { return db.Articles.Select(t => new Model.Article() { Author = MapUserEntityT

How to write dynamic LINQ queries using DBContext in C #

I am modifying my project to use DBContext instead of ObjectContext. My existing code var query = context.Vehicles.OrderBy("it.VehicleType.VehicleTypeID"). GroupBy("it.VehicleType.VehicleTypeID", "Min(it.ODO_Reading) AS MinRunVehi

How to add and consolidate lines sharing a user name in a list

My project is a game where users try to predict scores of football matches and are awarded points based off of different criteria. I'm using MVC and Entity Framework. I am trying to create a leaderboard that displays the total score for each user. I'

MVC - System.Threading.ThreadAbortException in a parallel task

In my MVC application, a superadministrator can set a queue of tasks such as updating database. So, when an admin adds an update to the queue, the controller starts a new tasks that works in a background. However, when you add a few tasks, the applic

Query Automap for projecting an anonymous type on a viewmodel

I have a very basic controller, which does a Linq to Entities query and I want to be able to project the results onto a viewmodel using AutoMapper - however I'm getting the error: cannot convert from 'System.Collections.Generic.List<AnonymousType#1>

How can NodaTime be used with EF Code First?

I really want to be able to use NodaTime in my Entity Framework Code First database projects but haven't found a "clean" way to do it. What I really want to do is this: public class Photoshoot { public Guid PhotoshootId{get; set;} public LocalDa

OData, Web Api 2, and deeply nested objects

I've been trying to find the answer to this and haven't had any luck. Assume I have a model that looks something like this: public class A { public int Id {get;set} public ICollection<B> Bs {get;set;} } public class B { public int Id {get;set} publi

Multi-mode search in Entity Framework

The code is listed below , is my code for multimode search in , i use now entity framework and i dont know how write this perfectly with less code string query = '"SELECT id From user"; if(filter1 != "" || filter2 != "&quo

How to get a single column with Entity Framework?

I have code to retrieve all columns from a entity class against a search criteria. But I want a specific column value instead of complete column values. My code is - Main main; main = repo.Find<Main>(m => m.Code == criteria.code); where Main is e

Unit of work for each module

I am currently building an MVC application, which has be broken down into multiple modules (as well as a generic class library). I have implemented a Unit Of Work pattern for my first module. This unit of work class contains a number of diffe

Integrity of data in Entity Framework

Are there any consensus as to what is considered the best method in always maintaining data integrity in Entity Framework. i.e. when adding or deleting entities, how do I make sure the loaded model is the most recent, and that nothing has changed on

Why do not we use a nullable Guid in this linq query?

I have this code to find the root node of a tree: Guid? currentNode = null; var root = db.RecursiveTrees.Where(x => x.ParentId == currentNode).ToList(); This query returns 0 results. If I run this query I get the expected row returned: var root = db.

mapping the private ownership entity code first

I am using EF 4.1 and was look for a nice workaround for the lack of enum support. A backing property of int seems logical. [Required] public VenueType Type { get { return (VenueType) TypeId; } set { TypeId = (int) value; } } private int TypeId { get

LINQ to Entities how to update a record

Okay, so I'm new to both EF and LINQ. I have figured out how to INSERT and DELETE but for some reason UPDATE seems to escape my grasp. Here is a sample of my code: EntityDB dataBase = new EntityDB(); Customer c = new Customer { Name = "Test", Ge