简体   繁体   中英

how can i add another object to an already defined IQueryable object?

I have IQueryable Products. now i want to add new product to this IQueryable object. so how do i do this?

我从没有尝试过,但是尝试使用products.Union(moreProducts)。

IQueryable doesn't have any methods for adding. See MSDN .

The IQueryable interface does not itself provide operations to add to the set of items. Are you using an ORM? Which one? Microsoft's Entity Framework implements IQueryable via the System.Data.Linq.Table<TEntity> class, which also has methods for adding entities (Attach, AttachAll).

您将不得不回退到实现IQueryable的类型。

IQueryable doesn't provide any guarantee of having a means to add items; In order to add items, you will need access to the data store behind the IQueryable. If you are using Linq to SQL, this would be the table. Your code in that case would look like DataContext.GetTable().InsertOnSubmit(aProduct).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM