快速linq to sql查询到带图像的表 [英] fast linq to sql query to table with images

查看:56
本文介绍了快速linq to sql查询到带图像的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天!

帮助PLZ ...



如何从数据库中正确选择信息......

例子......



i有

1表汽车哪里有Id,VIN

1 tabke CarImages我有id,carid(来自Car表)和Image作为二进制数据



我需要构建示例XML结构:

Good day!
Help plz...

how i can correctly select info from DB...
example...

i have
1 table Cars where have Id, VIN
1 tabke CarImages where I have id, carid (from Car table) and Image as binary data

I need to build sample XML struct:

<Cars>
<Car id="1" vin="CarVin13simbol" PhotosCount="2">
<Car id="2" vin="CarVin13simbol" PhotosCount="10">
<Car id="3" vin="CarVin13simbol" PhotosCount="0">
</Cars>



如何正确构建linq查询?所有我尝试 - 通过var QueryData示例下载所有数据(和图像)


How correctly build linq query? All i try - download all data (and images too) by var QueryData example

_dc.Cars.First(x => x.id == 1).CarPhotos.Count()



很多次我的程序执行和许多内存在使用(有时是outofmemoryexeption)



帮助plz ...对不起英语...不知道它:))


many time my program executing and many memory in use (sometimes outofmemoryexeption)

Help plz... sorry for English... bad know it :)

推荐答案

尝试这样的事情:

Try something like this:
var allCars = _dc.Cars.Select(x => new 
{ 
    x.id, 
    x.vin, 
    PhotosCount = x.CarPhotos.Count() 
});

var allCarsXml = allCars.AsEnumerable().Select(x => new XElement("Car",
    new XAttribute("id", x.id),
    new XAttribute("vin", x.vin),
    new XAttribute("PhotosCount", x.PhotosCount)
);

var xml = new XDocument(new XStreamingElement("Cars", allCarsXml));


这篇关于快速linq to sql查询到带图像的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆