Initializing strongly typed objects in LINQ to Entities

前端 未结 5 1474
别跟我提以往
别跟我提以往 2020-12-16 01:40

I have a plain old CLR object which is essentially a wrapper for two entity framework objects, I\'m doing this so I can pass this wrapper object to a strongly typed view in

5条回答
  •  既然无缘
    2020-12-16 02:02

    Why aren't you using the .AsEnumerable()? In that way, you won't need to create a parameterless constructor and that is what you want.

    Your code was almost good. Change it to this:

    public IEnumerable ListFoosWithBars(int userID)
    {
        IEnumerable tempBar = ListBarsByUserID(userID);
        IEnumerable results = (from f in _entities.FooSet.AsEnumerable()
                                           join b in tempBar on f.ID equals b.foos.ID
                                           select new FooWrapper(f, b));
        return results;
    }
    

    I had the same problem today. I had a class with one parameter constructor. This constructor filled a private readonly field which was returned by a property only with a get and not with a set.

提交回复
热议问题