English 中文(简体)
无法在 LINQ 选中 LINQ 时设置 enum 属性
原标题:Unable to set enum property during LINQ select

我有以下代码碎片

IQueryable<RssItem> rssItems = from prodotti prodotto in tuttiProdotti
                                               join marca in tutteMarche on prodotto.marca equals marca.id

                                               where prodotto.eliminato == 0
                                               orderby prodotto.id ascending
                                               select new GoogleShoppingRssItem
                                               {
                                                   Author = AUTHOR,
                                                   //Availability = prodotto.disponibilita > 0 ? AvailabilityType.instock : AvailabilityType.outofstock,
                                                   //Availability = AvailabilityType.instock,
                                                   Title = prodotto.titolo,
                                               };

当第一个版本的可用行未加注意时,我得到了 ArgumentExpeption , 说 value 不是类型 Edm.Int32 。 我认为它与 prodotto.disponibilita 属性有关,即 int? ? (但DB上没有 null 值)。 第二个版本,不检查产品数量, 也存在同样的例外。

只是在对第二版可用性设置进行了评论之后,该代码才最终起作用,并且对表达方式进行了评价。

221. 弹药的界定如下:

  [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
    [System.SerializableAttribute()]
    [XmlType(Namespace="http://base.google.com/ns/1.0")]
    [XmlRoot("availability", Namespace="http://base.google.com/ns/1.0", IsNullable=false)]
    public enum AvailabilityType {

        /// <remarks/>
        [XmlEnum("in stock")]
        instock,

        /// <remarks/>
        [XmlEnum("available for order")]
        availablefororder,

        /// <remarks/>
        [XmlEnum("out of stock")]
        outofstock,

        /// <remarks/>
        preorder,
    }

在 LINQ 选择语句中设置 < code>enum 属性是否有什么我应该知道的?

最佳回答

在 LINQ 选择的语句中设置 enum 属性, 我该知道些什么吗?

是 。 EF4 不支持 enums, 您无法在 Linq 到 Enities 查询中使用它们。 如果您在 Linq 到 Objects 查询中使用它们, 它应该有效 。 请尝试 :

IQueryable<RssItem> rssItems = (from prodotto in tuttiProdotti
                                join marca in tutteMarche on prodotto.marca equals marca.id
                                where prodotto.eliminato == 0
                                orderby prodotto.id ascending
                                select prodotto).ToList() // Now you switched to L2O
                               .Select(x => new GoogleShoppingRssItem
                                               {
                                                   Author = AUTHOR,
                                                   Availability = x.disponibilita > 0 ? AvailabilityType.instock : AvailabilityType.outofstock,
                                                   Title = x.titolo,
                                               });
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签