0

I have a model class that stores information in the datatbase. then I created a list test. This lists get xml data and puts its in a list.

so in my controller,

I have this linq query:

function somefunction()
{
    var mov = from m in db.Movies
                          select m;
    List<Movie> items = MyXMLExtract();//this gets xml file from a url, then returns a list<Movie>.
    var thistest = mov.ToList().Concat(items);; //I concatenate the two linq

    return thistest;
}

in my view I have this:

@model IEnumerable<Models.Movie>

however, everything in this view gives an error:

Unable to create a constant value of type 'Models.Movie'. Only primitive types or enumeration types are supported in this context.

I understand the error, but how to deal with it? Basically I am returning a list, and I am using Ienumerable, what to do? my view is just a foreach loop output the fields names.

both movie and items use the same db model from Movies.

this below gives me an error:

Object reference not set to an instance of an object.

if (!String.IsNullOrEmpty(searchString))
{
    thistest = thistest.Where(s => s.description.Contains(searchString)
                                || s.title.Contains(searchString)
                                || s.location.Contains(searchString));
}
4

1 回答 1

1

LINQ 尝试将列表项传递给 DB 并在 SQL Server 端连接它们。

改变 mov.Concat(items); 到 mov.ToList().Concat(items) 在连接之前从 SQL 中提取数据。

于 2013-10-01T17:43:27.670 回答