6

My error is:

Could not find an implementation of the query pattern for source type 'System.Data.Entity.Database'. 'Select' not found.

My relevent code is:

DatabaseEntities db = new DatabaseEntities();   
var whichUi = from UiType in db.Database
              select  AdvancedUi;

I am using the linq import (common answer on other threads).

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
user3658489
  • 63
  • 1
  • 1
  • 4
  • Please refer this answer: http://stackoverflow.com/a/8216107/213550 - db.Database is probably not implementing the `IEnumerable` interface. Also you should note that not only the reference for the library but `using` statement is required. – VMAtm Jul 15 '14 at 07:44
  • possible duplicate of [Could not find an implementation of the query pattern](http://stackoverflow.com/questions/8215773/could-not-find-an-implementation-of-the-query-pattern) – VMAtm Jul 15 '14 at 07:44
  • 5
    Sure that you have added using System.Linq;? – Rangesh Jul 15 '14 at 07:44
  • @VMAtm I don't understand the answer in that thread :/.. I'll give the using a try and let you know how it turns out – user3658489 Jul 15 '14 at 07:50
  • @restless By default all my classes are using linq (copy and pasted from the class = using System.Linq; ) – user3658489 Jul 15 '14 at 07:52
  • Can you post the code of the `DatabaseEntities.Database`? – VMAtm Jul 15 '14 at 07:52
  • @VMAtm Using a using didn't help (code - using (DatabaseEntities db = new DatabaseEntities()) { var whichUi = from UiType in db.Database select AdvancedUi; }) – user3658489 Jul 15 '14 at 07:55
  • @VMAtm There is no code, it's a database? Or am I misunderstanding? – user3658489 Jul 15 '14 at 07:56
  • Am I missing something or should the code say 'select UiType'? – DavidG Jul 15 '14 at 08:01
  • @DavidG My naming is bad I need to sort it out, I just want to get it working so I can properly start (which is why my query isn't in a method). The box highlighted in red is what I want to select http://prntscr.com/42u4e7 – user3658489 Jul 15 '14 at 08:04
  • 1
    You need to have 'select UiType.AdvancedUI' and more than likely from db.Database.UiTypes or equivalent. – DavidG Jul 15 '14 at 08:10

3 Answers3

3

I think your error is that you try to select something from .Database directly, not from the table. Instead of this code:

from UiType in db.Database

try out something like this:

from UiType in db.UiTypes
select UiType.AdvancedUi;

This should work as the table UiTypes will implemet the IEnumerable interface.

You should put your table name after the in keyword.
UiType is just a placeholder, and can be anything you want. Please, pay attention to the select clause - you must use the placeholder there, not the table name.

VMAtm
  • 27,943
  • 17
  • 79
  • 125
  • Pretty much what I wrote in the comments but also the select needs fixing. – DavidG Jul 15 '14 at 08:12
  • @VMAtm I don't have the option to do that http://prntscr.com/42u7nt Also, why uiTypeObject ; my table isn't called that is there a reason or just a typo? – user3658489 Jul 15 '14 at 08:21
  • @DavidG Please refer to the above comment > – user3658489 Jul 15 '14 at 08:21
  • Oh, I see! But now it gives this error http://prntscr.com/42u8y7 . I've spelt it correctly ><. @VMAtm P.S. Thank you both for your help – user3658489 Jul 15 '14 at 08:26
  • 1
    Like I said above you must put UiType.AdvancedUI – DavidG Jul 15 '14 at 08:31
  • @DavidG That doesn't work for me http://prntscr.com/42ub8l , http://prntscr.com/42ubcw . I honestly have no clue why :/.. On here it looks so simple.. http://msdn.microsoft.com/en-us/library/bb546142.aspx – user3658489 Jul 15 '14 at 08:36
  • 2
    If I'm honest I think you need a course in Linq basics, I'm sure it would solve all your issues. – DavidG Jul 15 '14 at 08:39
  • @DavidG Thanks a lot! I'll do this a few times to drill it into my head. Thanks again!! – user3658489 Jul 15 '14 at 08:41
  • @DavidG I'd love to be given that oppurtunity but for now it's just me , online resources and stackoverflow :P. – user3658489 Jul 15 '14 at 08:45
  • @user3658489 That's all you need, spend a couple of hours going through an online example (there are lots around) and you will understand each of the components of a Linq query. – DavidG Jul 15 '14 at 08:46
  • I think that he is missing using system.linq. otherwise how can you select a database directly. intellisense will not even offer you – Emil Mar 03 '17 at 12:54
0

In my case, I resolved the error by changing:

var results = db.MyStoredProc().Select(x => x);

Or,

var results = from x in db.MyStoredProc()
              select x;

To,

var results = db.MyStoredProc();    

HTH.

user8128167
  • 6,929
  • 6
  • 66
  • 79
0

The whole logic behind the query syntax/fluent syntax is to select an object as a whole or to select a property of an object.

Look at this following query:

var result = (from s in _ctx.ScannedDatas.AsQueryable()
                                  where s.Data == scanData
                                  select s.Id).FirstOrDefault();

Please note that after the where clause I am selecting only the Id property of the ScannedData object. So to answer your question, if AdvancedUi is a property of UiTypes class then your query should be more like:

var result = from UiType in db.UiTypes
             select UiType.AdvancedUi;

Alternatively if you want to return all data from a table say ScannedDatas, then your query will be:

var listResult = (from d in _ctx.ScannedDatas
                              select d).ToList();

Hope this answers your question my friend.

Abhay Shiro
  • 3,431
  • 2
  • 16
  • 26