Linq to SQL Error
-
I've got this Code:
System.Linq.IQueryable fdl = _db.object_localized_1_de.AsQueryable();
var artNrs = from item in fdl
where item.bedienungsanweisung.Contains(id)
&& item.article_number != null
select item.article_number;But i get this error:
Could not find an implementation of the query pattern for source type 'System.Linq.IQueryable'. 'Where' not found. Consider explicitly specifying the type of the range variable 'item'.
-
I've got this Code:
System.Linq.IQueryable fdl = _db.object_localized_1_de.AsQueryable();
var artNrs = from item in fdl
where item.bedienungsanweisung.Contains(id)
&& item.article_number != null
select item.article_number;But i get this error:
Could not find an implementation of the query pattern for source type 'System.Linq.IQueryable'. 'Where' not found. Consider explicitly specifying the type of the range variable 'item'.
What type of object does the
object_localized_1_de
collection contain? Either use the object type as the type parameter for the genericIQueryable<T>
interface:System.Linq.IQueryable<YOUR_TYPE_HERE> fdl = _db.object_localized_1_de.AsQueryable();
Or explicitly specify the type in the query:
var artNrs = from YOUR_TYPE_HERE item in fdl ...
Or use
var
to implicitly type thefdl
variable:var fdl = _db.object_localized_1_de.AsQueryable();
The first and third options will be identical. The second option will call the
Cast
method, which could affect the performance.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
What type of object does the
object_localized_1_de
collection contain? Either use the object type as the type parameter for the genericIQueryable<T>
interface:System.Linq.IQueryable<YOUR_TYPE_HERE> fdl = _db.object_localized_1_de.AsQueryable();
Or explicitly specify the type in the query:
var artNrs = from YOUR_TYPE_HERE item in fdl ...
Or use
var
to implicitly type thefdl
variable:var fdl = _db.object_localized_1_de.AsQueryable();
The first and third options will be identical. The second option will call the
Cast
method, which could affect the performance.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Okay thanks... But now i've this Code:
for (int i = 0; i < 3; i++)
{
var query = _db.object_localized_1_de.AsQueryable();
if (i == 1) { query = _db.object_localized_1_en.AsQueryable(); }
if (i == 2) { query = _db.object_localized_1_fr.AsQueryable(); }var artNrs = from item in query where item.bedienungsanweisung.Contains(id) && item.article\_number != null select item.article\_number; //...
}
And got this Errors:
Cannot implicitly convert type 'System.Linq.IQueryable' to 'System.Linq.IQueryable'. An explicit conversion exists (are you missing a cast?)
Cannot implicitly convert type 'System.Linq.IQueryable' to 'System.Linq.IQueryable'. An explicit conversion exists (are you missing a cast?)I don't want to use a cast, may you can help me please?
-
Okay thanks... But now i've this Code:
for (int i = 0; i < 3; i++)
{
var query = _db.object_localized_1_de.AsQueryable();
if (i == 1) { query = _db.object_localized_1_en.AsQueryable(); }
if (i == 2) { query = _db.object_localized_1_fr.AsQueryable(); }var artNrs = from item in query where item.bedienungsanweisung.Contains(id) && item.article\_number != null select item.article\_number; //...
}
And got this Errors:
Cannot implicitly convert type 'System.Linq.IQueryable' to 'System.Linq.IQueryable'. An explicit conversion exists (are you missing a cast?)
Cannot implicitly convert type 'System.Linq.IQueryable' to 'System.Linq.IQueryable'. An explicit conversion exists (are you missing a cast?)I don't want to use a cast, may you can help me please?
Your entities will have to implement a common interface, or inherit from a common base class, containing the properties you need to query:
interface ILocalizedObject
{
?PROPERTY_TYPE_HERE? bedienungsanweisung { get; }
?PROPERTY_TYPE_HERE? article_number { get; }
}class object_localized_1_de : ILocalizedObject
{
...
}class object_localized_1_fr : ILocalizedObject
{
...
}class object_localized_1_en : ILocalizedObject
{
...
}You'll then need to use that interface in your variable declaration:
for (int i = 0; i < 3; i++)
{
IQueryable<ILocalizedObject> query = _db.object_localized_1_de.AsQueryable();
if (i == 1) { query = _db.object_localized_1_en.AsQueryable(); }
if (i == 2) { query = _db.object_localized_1_fr.AsQueryable(); }var artNrs = from item in query where item.bedienungsanweisung.Contains(id) && item.article\_number != null select item.article\_number; ...
}
This will work due to generic covariance[^].
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Your entities will have to implement a common interface, or inherit from a common base class, containing the properties you need to query:
interface ILocalizedObject
{
?PROPERTY_TYPE_HERE? bedienungsanweisung { get; }
?PROPERTY_TYPE_HERE? article_number { get; }
}class object_localized_1_de : ILocalizedObject
{
...
}class object_localized_1_fr : ILocalizedObject
{
...
}class object_localized_1_en : ILocalizedObject
{
...
}You'll then need to use that interface in your variable declaration:
for (int i = 0; i < 3; i++)
{
IQueryable<ILocalizedObject> query = _db.object_localized_1_de.AsQueryable();
if (i == 1) { query = _db.object_localized_1_en.AsQueryable(); }
if (i == 2) { query = _db.object_localized_1_fr.AsQueryable(); }var artNrs = from item in query where item.bedienungsanweisung.Contains(id) && item.article\_number != null select item.article\_number; ...
}
This will work due to generic covariance[^].
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
I'm getting this error:
Cannot implicitly convert type 'System.Linq.IQueryable' to 'System.Linq.IQueryable'. An explicit conversion exists (are you missing a cast?)
Did I something wrong?
-
I'm getting this error:
Cannot implicitly convert type 'System.Linq.IQueryable' to 'System.Linq.IQueryable'. An explicit conversion exists (are you missing a cast?)
Did I something wrong?
Looks like you forgot to make your entity class implement the interface.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Looks like you forgot to make your entity class implement the interface.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Yes it works thank you...
-
I've got this Code:
System.Linq.IQueryable fdl = _db.object_localized_1_de.AsQueryable();
var artNrs = from item in fdl
where item.bedienungsanweisung.Contains(id)
&& item.article_number != null
select item.article_number;But i get this error:
Could not find an implementation of the query pattern for source type 'System.Linq.IQueryable'. 'Where' not found. Consider explicitly specifying the type of the range variable 'item'.
:thumbsup: Super! Thanks!