Linq to SQL question
-
Hi all, quick question, using the following
using(DataModel.DatabaseDataContext context = GetDatabaseContext()) var result = from b in context.Branches where b.Id == id select new Branch() { Id = b.Id, RowVersion = b.RowVersion.ToArray(), Name = b.Name, Description = b.Description };
I get a compiler error stating that an embedded statement cannot be a declaration or labbeled statement. I believe this is related to the return type from the Linq statement. Is anybody able to point me in the correct direction of what this type should be? I have tried several types and get the impression that I have a fundamental misunderstanding.Just racking up the postings
-
Hi all, quick question, using the following
using(DataModel.DatabaseDataContext context = GetDatabaseContext()) var result = from b in context.Branches where b.Id == id select new Branch() { Id = b.Id, RowVersion = b.RowVersion.ToArray(), Name = b.Name, Description = b.Description };
I get a compiler error stating that an embedded statement cannot be a declaration or labbeled statement. I believe this is related to the return type from the Linq statement. Is anybody able to point me in the correct direction of what this type should be? I have tried several types and get the impression that I have a fundamental misunderstanding.Just racking up the postings
Did I understand correctly that you're querying for branches which have a specific id? I that's correct, I think it could be something like:
using(DataModel.DatabaseDataContext context = GetDatabaseContext()) {
var result = from b in context.Branches
where b.Id == id
select b;
foreach(Branch branch in result) {
...
}
}The need to optimize rises from a bad design.My articles[^]