Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
XML Anonymous Types
Message
General information
Forum:
ASP.NET
Category:
XML
Environment versions
Environment:
C# 5.0
OS:
Windows 10
Network:
Windows Server 2016
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01649231
Message ID:
01649296
Views:
34
I think you'll need to use an IEnumerable for the XML query. If you are creating the anonymous type query in the same method you could use that for the XML : var xx = from p in q.AsEnumerable()........


>Hi Cetin,
>
>So following your brilliant PS I got it to work as follows:
>
>
>                using (var context = new PICSEntities(Config.model.SqlServer))
>                {
>                    var q = from p in context.Parcels
>                            join t in context.TransactionDetails on p.Parcels_Id equals t.Parcels_Id
>                            select new
>                            {
>                                Parcels_Id = p.Parcels_Id,
>                                Goods = p.GoodsType.Description,
>                                Inventory = p.ParcelInventoryType.Description,
>                                RSReference = p.RSReference,
>                                Transaction_Nr = t.TransactionHeaders_Id,
>                                Transaction_Type = t.TransactionHeader.TransactionType.Description,
>                                Date = t.TransactionHeader.TransactionDate,
>                                Weight = t.Weight,
>                                Amount = t.Amount
>                            };                 
>               }
>
>
>So I thought I'd follow your no less brilliant suggestion and came up with this:
>
>
>            using (var context = new PICSEntities(Config.model.SqlServer))
>            {
>                XDocument asXmlDocument =
>                    new XDocument(
>                        new XDeclaration("1.0", "utf-8", ""),
>                            new XElement("Parcels",
>                              from p in context.Parcels
>                              join t in context.TransactionDetails on p.Parcels_Id equals t.Parcels_Id
>                              select new XElement("Parcel",
>                                  new XAttribute("Parcels_Id", p.Parcels_Id),
>                                  new XAttribute("Goods",p.GoodsType.Description),
>                                  new XAttribute("Inventory", p.ParcelInventoryType.Description),
>                                  new XAttribute("RSReference", p.RSReference),
>                                  new XAttribute("Transaction_Nr", t.TransactionHeaders_Id),
>                                  new XAttribute("Transaction_Type", t.TransactionHeader.TransactionType.Description),
>                                  new XAttribute("Date", t.TransactionHeader.TransactionDate),
>                                  new XAttribute("Weight", t.Weight),
>                                  new XAttribute("Amount", t.Amount)
>                                )
>                            )
>                        );
>                using (XmlWriter xw = XmlWriter.Create(@"c:\docs\q.xml"))
>                {
>                    asXmlDocument.Save(xw);
>                }
> 
>           }
>
>
>But that breaks : System.NotSupportedException: 'Only parameterless constructors and initializers are supported in LINQ to Entities.'
>
>I'm lost here. Don't even now where to start looking.
Previous
Reply
Map
View

Click here to load this message in the networking platform