How to do this inside in list (user.image = plugins.LoadImage(user.Image))
LoadImage is function which return image in the Form BitmapImage
var query = (
from user in chatDBContext.tbl_User
select new
{
user.FirstName, user.LastName, user.Gender, user.Email,
user.DoB, user.Address, user.City, user.State,user.Country,
user.Quote, user.username, (user.image = plugins.LoadImage(user.Image))
}
).ToList();
Consider that plugins.LoadImage(user.Image))
can't be executed in a linq2sql (nor EntityFramework) context.
So: execute the query first, take objects in memory (you can do that by call .ToList()
or .ToArray()
for example), then retrieve the image.
// database oriented query
var query = from user in chatDBContext.tbl_User
select user;
// take objects in memory THEN retrieve images
var objects = query.ToList().Select(user => new
{
user.FirstName, user.LastName, user.Gender, user.Email,
user.DoB, user.Address, user.City, user.State,
user.Quote, user.username, image = plugins.LoadImage(user.Image)
});
Consider that you can avoid repeat all user
fields simply selecting the entire object instead all single properties:
var objects = query.ToList().Select(user => new
{
user, image = plugins.LoadImage(user.Image))
});
Usage:
foreach (var obj in objects)
{
Console.WriteLine(obj.user.FirstName);
Console.WriteLine(obj.user.LastName);
// and so on all user properties
Console.WriteLine(obj.image.Height); // just example
}
EDIT (clarification)
in your source code there is 2 distinct problems:
user.image
property (i don't know if there is any property named image
in your User
class, anyway): you can't do an assignment into an anonymus object constructor. Instead, like my example or the other answer example, you should declare an image
property right into the anonymus object initializer.new { user.image = plugins.LoadImage(user.Image) }
should becomes
new { image = plugins.LoadImage(user.Image) }
Convert.ToInt32()
, .ToString()
, etc.For more info about the code that you can execute into a linq2sql query take a look here, otherwise for EntityFramework here
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments