English 中文(简体)
准则对实体并不承认Int32的方法
原标题:LINQ to Entities does not recognize the method Int32
public ActionResult ReadXMLDevices(int groupID)
{             
    var query = from k in XMLEntities.unassigneditems
    where k.DevOrAcc == true && k.Group == groupID
    select k;

    var view_query = from i in query
                     select new GetFreeDevices
                     {
                         MArticleNumber = i.ArticleNumber,
                         MFirmware = i.Firmware,
                         MGroup = i.Group,
                         MName = i.Name,
                         MSoftware = i.SoftwareVersion,
                         SA = GetNumberOfDevices(i.ArticleNumber,2),
                         STH = GetNumberOfDevices(i.ArticleNumber,3),
                         SASTH = GetNumberOfDevices(i.ArticleNumber,7)
                     };
    return PartialView(view_query);
}

public int GetNumberOfDevices(string artNo,int loc)
{
    var num_dev = (from k in XMLEntities.deviceview
                   where k.Reserved == false && k.Sold == false && k.LocationNameId == loc && k.ArticleNumber == artNo
                   select k).Count();
    return num_dev;
}

错误:

准则对各实体并不承认Int32 GetNumberOfDevices(系统)的方法。 浏览法,Int32)方法,这一方法不能转化为储存的表述。 如何解决这一问题?

最佳回答

您可以把询问分为两部分,以确保名单在打上方法>之前的中间。 您可以通过将结果转换为,或在此情况下改成List<GetFreeDevices>。 这样,各实体的LinQ就不必做任何来自XML的翻译,你可以使用)。

var view_query = (from i in query
     select new GetFreeDevices
     {
        MArticleNumber = i.ArticleNumber,
        MFirmware = i.Firmware,
        MGroup = i.Group,
        MName = i.Name,
        MSoftware = i.SoftwareVersion

     }).ToList();
var result_query = from i in query
     select new GetFreeDevices
     {
        MArticleNumber = i.MArticleNumber,
        MFirmware = i.MFirmware,
        MGroup = i.MGroup,
        MName = i.MName,
        MSoftware = i.MSoftware,
        SA = GetNumberOfDevices(i.MArticleNumber,2),
        STH = GetNumberOfDevices(i.MArticleNumber,3),
        SASTH = GetNumberOfDevices(i.MArticleNumber,7)
     };
return PartialView(result_query);

请注意,最后一份声明要求部分意见接受名单或<代码>。 缩略语 IQueryable。

问题回答

另一种容易的方式。

第一,将数据从数据库上载到记忆:

// ...
var query_view = from i in query
                 select i;

query_view.Load();
// ...

那么,你想要的是lin子,而不是L2E:

var view_query_1 = from i in DbContext.myEntities.Local
                 select new GetFreeDevices
                 {
                     MArticleNumber = i.ArticleNumber,
                     MFirmware = i.Firmware,
                     MGroup = i.Group,
                     MName = i.Name,
                     MSoftware = i.SoftwareVersion,
                     SA = GetNumberOfDevices(i.ArticleNumber,2),   //
                     STH = GetNumberOfDevices(i.ArticleNumber,3),  // These are now ok!
                     SASTH = GetNumberOfDevices(i.ArticleNumber,7) //
                 };
    return PartialView(view_query_1.AsEnumerable());

你们可以利用这一骗局,采用L2E不支持的任何方法。





相关问题
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. ...

热门标签