繁体   English   中英

Linq to sql进入对象列表

[英]Linq to sql into object list

请考虑以下表格:

TblDocument

docID,  levelID, name 
101,    201,     AAA 
102,    201,     BBB 
103,    201,     CCC 
104,    202,     DDD 
105,    202,     EEE 

网页

pgID, docID, pgNo
1,    101,   1
2,    102,   1
3,    102,   2
4,    103,   1
5,    104,   1
6,    105,   1

TblFieldName

fieldNameID, levelID, fieldName  
1,           201,     WrittenBy  
2,           201,     VerifiedBy 
3,           201,     DocumentName

TblFieldValue

docID,  fieldNameID, fieldValue 
101,    1,           James 
101,    2,           Bond  
101,    3,           Essay on something  
102,    1,           Krister
102,    2,           Holm
102,    3,           Dame it or not!  

public class Document
{
  public int DocID {get; set;}
  public int LevelID {get; set;}
  public string Name {get; set;}

  public List<Field> Metadata
  {
     get { return (_fields); }
     set { _fields = value; }
  }       
  private List<Field> _fields = new List<Field>();
}


public class Field
    {
      public FieldNameID {get; set;}
      public FieldName {get; set;}
      public FieldValue {get; set;}
    }

现在,我试图使用运行良好的linq从数据库中获取数据。

using (DBDataContext context = new DBDataContext())
{
  List<Document> doc  = (from d in context.TblDocuments
     join p in context.TblPages on d.docID equals p.docID into dpgrp
     from dp in dpgrp.Where(f => f.docID == d.docID).DefaultIfEmpty()
     where d.levelID == 201
     select new Document
     {
       DocumentID = d.docID,
       LevelID = d.levID
     }).ToList<Document>();
 }

有人可以帮我如何获取列表中的字段值吗?

using (DBDataContext context = new DBDataContext())
{
  List<Document> doc  = (from d in context.TblDocuments
     join p in context.TblPages on d.docID equals p.docID into dpgrp
     from dp in dpgrp.Where(f => f.docID == d.docID).DefaultIfEmpty()
     where d.levID == 201
     select new Document
     {
       DocumentID = d.docID,
       LevelID = d.levID
       Metadata = ???????            // how to achieve this? as it is a list
     }).ToList<Document>();
 }

我建议对L2S使用DataLoadOptions

options.LoadWith<Document>(d => d.Metadata);

如何搜索 LINQ SQL LIST 中的值<object><div id="text_translate"><p>我有一个名为 Quotes 的 SQL 表。</p><p> 在 C# 中,我拥有的用户:</p><pre> Public class Locations { public string cityname { get; set; } } List&lt;Locations&gt; = new puLocations List&lt;Locations&gt; // Pickup Locations List&lt;Locations&gt; = new delLocations List&lt;Locations&gt; // Delivery Locations</pre><p> 现在我想用这些列表搜索我的报价表.. 像这样的东西(显然这不起作用)</p><pre> var quotes = from q in db.Quotes where q.PULocations in puLocations //puLocatiosn is the list&lt;Locations&gt; and q.DELLocations in delLocations select q;</pre><p> 所以我希望它返回任何匹配项.. 即如果在 pu 位置我有黄金海岸、悉尼、布里斯班。 和交货地点我有珀斯,霍巴特它应该返回黄金海岸 -&gt; 珀斯黄金海岸 -&gt; 霍巴特悉尼 -&gt; 珀斯悉尼 -&gt; 黄金海岸....等(如果这些报价存在)</p></div></object>

[英]how to search LINQ SQL where value in LIST<object>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C#Web API linq到SQL List对象 Linq to entities - SQL Query - 其中list包含具有2个属性(或更多)的对象 自定义对象列表-与SQL&#39;Like&#39;子句相似的Linq过滤 如何搜索 LINQ SQL LIST 中的值<object><div id="text_translate"><p>我有一个名为 Quotes 的 SQL 表。</p><p> 在 C# 中,我拥有的用户:</p><pre> Public class Locations { public string cityname { get; set; } } List&lt;Locations&gt; = new puLocations List&lt;Locations&gt; // Pickup Locations List&lt;Locations&gt; = new delLocations List&lt;Locations&gt; // Delivery Locations</pre><p> 现在我想用这些列表搜索我的报价表.. 像这样的东西(显然这不起作用)</p><pre> var quotes = from q in db.Quotes where q.PULocations in puLocations //puLocatiosn is the list&lt;Locations&gt; and q.DELLocations in delLocations select q;</pre><p> 所以我希望它返回任何匹配项.. 即如果在 pu 位置我有黄金海岸、悉尼、布里斯班。 和交货地点我有珀斯,霍巴特它应该返回黄金海岸 -&gt; 珀斯黄金海岸 -&gt; 霍巴特悉尼 -&gt; 珀斯悉尼 -&gt; 黄金海岸....等(如果这些报价存在)</p></div></object> 如何在连接两个表时将Linq中的匿名对象列表返回给Sql 退货清单 <Object> 从Linq SQL(Lambda)使用join和where DataContext对象(LINQ to SQL) 带有列表的LINQ中的SQL IN查询 LINQ to SQL中的订单列表 在LINQ中分页到SQL到列表
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM