[CSHARP-1691] Select with create new object throw exception Created: 20/Jun/16  Updated: 15/Jun/22  Resolved: 15/Jun/22

Status: Closed
Project: C# Driver
Component/s: Linq, LINQ3
Affects Version/s: 2.2.4
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Ilya Assignee: Robert Stam
Resolution: Duplicate Votes: 1
Labels: triaged
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows


Issue Links:
Duplicate
duplicates CSHARP-3922 LINQ3: support calls to constructors ... Closed
is duplicated by CSHARP-1963 Select with create new object not sup... Closed
Epic Link: CSHARP-3615

 Description   

Hello. In c# driver version 2.0.1.-rc this is code was worked.

public class Person
{
public string Id

{ get; set; }
public string Name { get; set; }

}

public class SubObject
{
public Person Pers

{ get; set; }
public string SomeData { get; set; }

public SubObject(Person pers, string someData)

{ Pers = pers; SomeData = someData; }

}

static void Main(string[] args)
{
MongoClient client = new MongoClient("mongodb://localhost");
var database = client.GetDatabase("TestDataBase");
var objectsCollection = database.GetCollection<Person>("TestCollection");
objectsCollection.Database.DropCollection(objectsCollection.CollectionNamespace.CollectionName);

var person = new Person()

{ Id = "12", Name = "Alex" }

;
objectsCollection.InsertOne(person);
person = new Person()

{ Id = "34", Name = "Timmy" }

;
objectsCollection.InsertOne(person);

var result1 = objectsCollection.AsQueryable().Where(o => o.Name.Length > 4).ToList(); // return 1 object
var result2 = objectsCollection.AsQueryable().Where(o => o.Name.Length > 4).Select(o => new SubObject(o, "test text")).ToList();
} // this code worked in 2.0.1-rc, but don't work in 2.2.4

This is bug or not?



 Comments   
Comment by Robert Stam [ 15/Jun/22 ]

This ticket was originally opened against LINQ2, but we're no longer enhancing LINQ2. We have an equivalent ticket CSHARP-3922 for the same feature in LINQ3.

Comment by Ilya [ 25/Jul/16 ]

Can anybody comment this issue?

Comment by Ilya [ 20/Jun/16 ]

Exception: An unhandled exception of type 'System.NotSupportedException' occurred in MongoDB.Driver.dll
Additional information: $project or $group does not support

{document}
Generated at Wed Feb 07 21:40:23 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.