C# 7.0 Value Tuple compile error?
It works for me, create a tuple first and convert it to a ValueTuple: var post = iPostService.GetAll(). Select(x => new Tuple<string, string>(x.Title, x.Author).ToValueTuple())
It works for me, create a tuple first and convert it to a ValueTuple: var post = iPostService.GetAll(). Select(x => new Tuple<string, string>(x.Title, x.Author).ToValueTuple())
It is worth knowing that the Entity Framework supports both to Linq to Entities and Entity SQL. If you find yourself wanting to do deletes or updates that could potentially affect many records you can use the equivalent of ExecuteNonQuery. In Entity SQL this might look like Using db As New HelloEfEntities Dim qStr = … Read more
You should be able to force the query to use LINQ to Objects rather than LINQ to Entities for the grouping, using a call to the AsEnumerable extension method. Try the following: DateTime firstDay = GetFirstDayOfFirstWeekOfYear(); var userTimes = from t in context.TrackedTimes.Where(myPredicateHere).AsEnumerable() group t by new {t.User.UserName, WeekNumber = (t.TargetDate – firstDay).Days / 7} … Read more
A simple way of doing this is to order by Guid.NewGuid() but then the ordering happens on the client side. You may be able to persuade EF to do something random on the server side, but that’s not necessarily simple – and doing it using “order by random number” is apparently broken. To make the … Read more
Very late to your question, I had the same issue and discovered that the entity framework designer had identified my “ScoreId” column (relative to your PersonModelScore table) as a primary key column. I changed my setting to false for my ScoreId, and all worked well afterward.
Just modify one of the returned entities: Customer c = (from x in dataBase.Customers where x.Name == “Test” select x).First(); c.Name = “New Name”; dataBase.SaveChanges(); Note, you can only update an entity (something that extends EntityObject, not something that you have projected using something like select new CustomObject{Name = x.Name}
You could use the EntityFunctions.DiffDays method EntityFunctions.DiffDays(product.EventDate, DateTime.Now) //this will return the difference in days UPDATE EntityFunctions is now obsolete so you should use DBFunctions instead. System.Data.Entity.DbFunctions.DiffDays(product.EventDate, DateTime.Now)
To show the created SQL commands for debugging in EF using System.Data.Objects; … var sqlQuery = query as ObjectQuery<T>; var sqlTrace = sqlQuery.ToTraceString(); AFAIK there are no commands to create DB’s or do any sort of DDL work. This is design limitation of the “Entity SQL” language The EDMX design surface will map your current … Read more
This is a great question. First of all, here are a couple of workarounds that come to mind (they all require changes to the query): First workaround This one maybe a bit obvious and unfortunately not generally applicable: If the selection of items you would need to pass over to Enumerable.Contains already exists in a … Read more
EF Core 5.0 is introducing Filtered Include soon. var blogs = context.Blogs .Include(e => e.Posts.Where(p => p.Title.Contains(“Cheese”))) .ToList(); Reference: https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-5.0/whatsnew#filtered-include