score:1
In your context DbContext
is missing - so Linq to Entity can not find corresponding implementation of the query. And also DbContext operates with the
DbSets - so try:
public class MedewerkerMeldingContext : DbContext
{
public MedewerkerMeldingContext () : base(ConnectionStringKey)
{
};
public DbSet<medewerker> medewerker { get; set; }
public DbSet<medewerker_melding> medewerker_melding { get; set; }
}
then
using (var context = new MedewerkerMeldingContext())
{
var medewerkers = context.medewerker;
var medewerker_meldings = context.medewerker_melding;
var testQuery = from m in medewerkers
join mm in medewerker_meldings on m.ID equals mm.medewerkerID
where m.ID == id
select new MedewerkerMeldingViewModel
{
ID = m.ID,
roepnaam = m.roepnaam,
voorvoegsel = m.voorvoegsel,
achternaam = m.achternaam,
tussenvoegsel = m.tussenvoegsel,
meisjesnaam = m.meisjesnaam,
datum_in_dienst = m.datum_in_dienst,
datum_uit_dienst = m.datum_uit_dienst,
aantal_km_woon_werk = m.aantal_km_woon_werk,
maandag = m.maandag,
ma_van = m.ma_van,
ma_tot = m.ma_tot,
dinsdag = m.dinsdag,
di_van = m.di_van,
di_tot = m.di_tot,
woensdag = m.woensdag,
wo_van = m.wo_van,
wo_tot = m.wo_tot,
donderdag = m.donderdag,
do_van = m.do_van,
do_tot = m.do_tot,
vrijdag = m.vrijdag,
vr_van = m.vr_van,
vr_tot = m.vr_tot,
zaterdag = m.zaterdag,
za_van = m.za_van,
za_tot = m.za_tot,
zondag = m.zondag,
zo_van = m.zo_van,
zo_tot = m.zo_tot,
medewerkerID = mm.medewerkerID,
meldingID = mm.meldingID,
datum_van = mm.datum_van,
datum_tot = mm.datum_tot,
MM_ID = mm.ID
};
Debug.WriteLine("Debug testQuery" + testQuery);
var getQueryResult = testQuery.ToList();
Debug.WriteLine("Debug getQueryResult: " + getQueryResult);
var resultDictionary = getQueryResult.GroupBy(x => x.ID).ToDictionary(y => y.Key, z => z.ToList());
Debug.WriteLine("resultDictionary: " + resultDictionary);
var firstItem = resultDictionary.Values.First();
Debug.WriteLine("FirstItem: " + firstItem);
var Entity = new newEntity
{
//ID = firstItem.ID,
ID = firstItem.Select(x => x.ID).First(),
roepnaam = firstItem.Select(x => x.roepnaam).First(),
voorvoegsel = firstItem.Select(x => x.voorvoegsel).First(),
achternaam = firstItem.Select(x => x.achternaam).First(),
tussenvoegsel = firstItem.Select(x => x.tussenvoegsel).First(),
meisjesnaam = firstItem.Select(x => x.meisjesnaam).First(),
datum_in_dienst = firstItem.Select(x => x.datum_in_dienst).First(),
datum_uit_dienst = firstItem.Select(x => x.datum_uit_dienst).First(),
aantal_km_woon_werk = firstItem.Select(x => x.aantal_km_woon_werk).First(),
maandag = firstItem.Select(x => x.maandag).First(),
ma_van = firstItem.Select(x => x.ma_van).First(),
ma_tot = firstItem.Select(x => x.ma_tot).First(),
dinsdag = firstItem.Select(x => x.dinsdag).First(),
di_van = firstItem.Select(x => x.di_van).First(),
di_tot = firstItem.Select(x => x.di_tot).First(),
woensdag = firstItem.Select(x => x.woensdag).First(),
wo_van = firstItem.Select(x => x.wo_van).First(),
wo_tot = firstItem.Select(x => x.wo_tot).First(),
donderdag = firstItem.Select(x => x.donderdag).First(),
do_van = firstItem.Select(x => x.do_van).First(),
do_tot = firstItem.Select(x => x.do_tot).First(),
vrijdag = firstItem.Select(x => x.vrijdag).First(),
vr_van = firstItem.Select(x => x.vr_van).First(),
vr_tot = firstItem.Select(x => x.vr_tot).First(),
zaterdag = firstItem.Select(x => x.zaterdag).First(),
za_van = firstItem.Select(x => x.za_van).First(),
za_tot = firstItem.Select(x => x.za_tot).First(),
zondag = firstItem.Select(x => x.zondag).First(),
zo_van = firstItem.Select(x => x.zo_van).First(),
zo_tot = firstItem.Select(x => x.zo_tot).First()
};
Debug.WriteLine("Entity: " + Entity);
var plainValues = resultDictionary.Values.SelectMany(x => x).ToList();
var resultSchedule = plainValues.Select(x => new medewerker_melding
{
medewerkerID = x.medewerkerID,
meldingID = x.meldingID,
datum_van = x.datum_van,
datum_tot = x.datum_tot,
ID = x.MM_ID
}).ToList();
Entity.medewerker_melding = resultSchedule;
}
score:1
You need to check whether MedewerkerMeldingContext dbC = new MedewerkerMeldingContext();
is implementing IEnumerable<T>
else, you will not be able to preform the desired action on the table.
This kind of error (Could not find an implementation of the query pattern) usually occurs when:
- You are missing LINQ namespace usage (
using System.Linq
)- Typeyou are querying does not implement
IEnumerable<T>
What i'd recommend, first check the namespace.
Second check for the IEnumerable<T>
implementation.
Your query is good enough, you take the context and perform the linq, no issue here. It is 90% that you forgot the namespace since context is already implementing the IEnumerable<T>
interface.
Source: stackoverflow.com
Related Articles
- creating Linq to sqlite dbml from DbLinq source code
- Get 1 record from 2 tables ASP.NET
- Can't add a new record with an integer value into database by using linq from code C#
- IQueryable two tables from Code First Entity Framework
- c# Linq or code to extract groups from a single list of source data
- Join multiple tables and return last record from table 2
- find record from referenced tables of primary key column
- Listing data from multiple tables but as 1 record
- Join Parent, Child and GrandChild tables with latest record from grandchild table using LinQ in C#
- Creating a LINQ select from multiple tables
- Linq. Select from multiple tables
- How to load just the last record from entity with LINQ?
- How to inner join tables from different Data Context?
- Joining tables from two databases using entity framework
- Enumerable.Empty<T>().AsQueryable(); This method supports the LINQ to Entities infrastructure and is not intended to be used directly from your code
- Accessing Results View from variable in code
- Generating the Shortest Regex Dynamically from a source List of Strings
- How to understand the following C# linq code of implementing the algorithm to return all combinations of k elements from n
- Get a Maximum Date value from X tables in DataSet
- LINQ to SQL: Complicated query with aggregate data for a report from multiple tables for an ordering system
- Picking random record from Entity Framework database without OrderBy
- How to find duplicate record using Linq from DataTable
- select n records from nth record in linq
- linq query to join two tables and get the count from one table values from the other
- Select records count from multiple tables in a single query
- How to pass LinQ Expressions from F# to C# code
- How to reuse a linq expression for 'Where' when using multiple source tables
- linq join query get single record from second table
- Using LINQ to delete an element from a ObservableCollection Source
- Joining two tables with LINQ while also returning null records from the second table
- What is the behaviour when returning a query result through a function and then continuing to query on that result?
- How do I retrieve only certain subobjects in LINQ?
- Using Where() with a dynamic Func fails, but works with a hard coded Where() clause
- How to do an outer join in LINQ?
- Which approach is better in LINQ?
- Return not behaving as i expect
- Linq query is not populating Child Collection
- Convert sql query with multiple inner joins to LINQ
- ViewBag select list LINQ table join
- LINQ - Set element in Dictionary to empty where DateTime value is oldest
- Remove similar items from List
- Retrieving all values from IGrouping
- Using query expressions for Unicode strings with LINQ
- SQL query to linq syntax
- Cascade MdiChildren
- How can I get percentage in LINQ?
- add MAX to existing criteria in LINQ query
- User Details Don't Show Up Using Pagination
- complex fetch with linq
- Understanding LINQ subquery