score:3
Accepted answer
I'm not 100% sure because you don't specify, but I'm guessing that your userGroup.Users
property is a navigation property generated by the EDMX model, so the entity collection is already created for you, all you need to do is add your users to the collection.
var userGroups = this.ObjectContext.UserGroups;
foreach (var userGroup in userGroups )
{
var ussers = this.ObjectContext.Users.Where(f => f.UserGroupID == item.ID && f.IsActive == true);
foreach(var user in ussers)
userGroup.Users.Add(user);
}
Source: stackoverflow.com
Related Articles
- How to convert IQueryable to EntityCollection
- Convert string[] to int[] in one line of code using LINQ
- Convert an IQueryable linq query to IEnumerable<T> cancels out linq optimized way to work?
- How to convert IQueryable to DataTable
- Convert IGrouping to IQueryable
- Execute expression on another IQueryable source
- LINQ Source Code Available
- Convert Linq ObjectQuery IQueryable to IEnumerable
- .NET 4 Code Contracts: "requires unproven: source != null"
- Cannot convert source type to target type List<KeyValuePair> Linq
- Convert IQueryable to Custom Class
- convert foreach loop to linq code
- Cannot convert source type system.nullable to target type int
- Convert IQueryable to IOrderedQueryable
- Unit testing code using IQueryable
- Linq to sql convert IQueryable to Dataset
- How might I convert this SQL code to LINQ?
- creating Linq to sqlite dbml from DbLinq source code
- Does LINQ convert code to SQL queries
- How do i convert this linq code to inline sql
- Convert this code to LINQ?
- How to convert this recursive code to Linq
- How to convert this code to LINQ?
- Convert this LINQ code back to a Loop (or Why is this object sometimes null)
- convert linq to object query to sql query (no linq to sql code or datacontext)
- Convert piece of code into LINQ (short syntax)
- Cannot build the Test project for LINQ IQueryable Toolkit (IQToolkit) - Code 9009
- Convert code that uses Linq to code that does not
- Linq - how to convert this code to linq
- EF code first cannot convert type to int
- TypedParameterExpression with Raven DB Any query
- Order by fields in an anonymous type
- Sorting XDocument elements based on InnerXML
- Populating child collection property with LINQ sub-query
- Linq: Join 2 tables that share one column name (with different data)
- Linq to NHibernate: 'System.Linq.EnumerableQuery`1[Entity]' cannot be converted
- EF Core 2.2: Add timezone conversion to a datetime2 column on select, groupby and/or where (Modify/enrich property mapping on a query)
- What is the difference between LINQ ToDictionary and ToLookup
- How to sort XML in LINQ C# by an attribute value? Also MVC
- How to query a RavenDb document based on the existence of a property
- Linq to Entities Query -
- How to find a string in DataGridView from TextBox?
- Convert GUID to string Entity Framework
- Fastest Conversion of Array of Guid to String and Back?
- LINQ query to select object and count
- Linq Where Condtion For Different Types
- Add a single query result to a List
- Convert multi-rows values into Collection(List) in LINQ
- Adding Summed columns together using Linq
- linq: what is the expression tree syntax for cross join