Linq to sql - Insert new rows

F

Fritjolf

Hi.

There must be something I missed...

If I do a simple linq query like this:
var sections = from s in
ProjectGlobal.rd.ER_Person_Sections
where s.Person_Id == "10"
select s;
The result is shown in a grid and a new itemrow is visible last in the
grid. I can also change values in the grid.

But if I change the "select s" with specific return values:
select new { s.Person_Id, s.Section_Code, s.ER_Section.SectionName };

The new row is not visible and I can't change any values. The dataset
seems read only.

Why is this?

Best regards,

Fritjolf
 
M

Mr. Arnold

Fritjolf said:
Hi.

There must be something I missed...

If I do a simple linq query like this:
var sections = from s in
ProjectGlobal.rd.ER_Person_Sections
where s.Person_Id == "10"
select s;
The result is shown in a grid and a new itemrow is visible last in the
grid. I can also change values in the grid.

But if I change the "select s" with specific return values:
select new { s.Person_Id, s.Section_Code, s.ER_Section.SectionName };

The new row is not visible and I can't change any values. The dataset
seems read only.

#1 It's not a dataset or datatable so drive that terminology from your
mind. It's a 'collection' of objects and objects have properties.
Why is this?

#2 You did a 'New' which is a New Shape and is selecting the properties
out of the collection of objects you quired, which is a new collection
of objects you have created and has nothing to do with the collection of
objects they were derived from in this case.
 
F

Fritjolf

#1 It's not a dataset or datatable so drive that terminology from your
mind. It's a 'collection' of objects and objects have properties.




#2 You did a 'New' which is a New Shape and is selecting the properties
out of the collection of objects you quired, which is a new collection
of objects you have created and has nothing to do with the collection of
objects they were derived from in this case.– Skjul sitert tekst –

– Vis sitert tekst –



Hi Arnold and thanx for your reply.

#1: Yes, I know it's a list of object instances, but I really need to
focus on this, so thanx! 10 years of records and datasets isn't easy
to shake off.

#2: Tihs answer disturbs me.... Because if I understand you correctly
I can't join simple data in a grid and have edit and insert options???
I have a person table, a section table and a PersonSection table (to
enable many:many relationship). The person is shown in databounded
textboxes and I have a grid below showing the sections for that
person. In this grid I want to show section code (which is part of the
primary key in PersonSection table) and I want to show section name,
which I must get from the section table. I must use the "new" keyword
to manage this. Are you telling me this can't be done... ?

Why can't linq figure this join out?
It knows I'm getting values from the table ER_Person_Section. From
it's own description (made from the object designer) it knows what
field is the PK etc etfc... hmmm....

I hope someone can help me with this and clerify things for me...

regards,
Fritjolf
 
M

Mr. Arnold

Fritjolf said:
Hi Arnold and thanx for your reply.

#1: Yes, I know it's a list of object instances, but I really need to
focus on this, so thanx! 10 years of records and datasets isn't easy
to shake off.

#2: Tihs answer disturbs me.... Because if I understand you correctly
I can't join simple data in a grid and have edit and insert options???
I have a person table, a section table and a PersonSection table (to
enable many:many relationship). The person is shown in databounded
textboxes and I have a grid below showing the sections for that
person. In this grid I want to show section code (which is part of the
primary key in PersonSection table) and I want to show section name,
which I must get from the section table. I must use the "new" keyword
to manage this. Are you telling me this can't be done... ?

You're doing a 'new' shape and only selecting properties out based on
the query that are going to be created for a 'new' object or objects as
the results coming out. This object or objects created by using a 'new'
have no relationship to anything on the model in context with anything
an entity or entities on the model.

You have to do things in the context they were started in and that 'new'
is a different context.

That's why when you do something, as in your example without using the
'new', CUD is in the proper context, can be done and Linq-2-SQL knows to
do it.

You can have R for the controls but that means for you, you would need
to take complete control of the CUD operations through code using
Linq-2-SQL.

Why can't linq figure this join out?
It knows I'm getting values from the table ER_Person_Section. From
it's own description (made from the object designer) it knows what
field is the PK etc etfc... hmmm....

Linq-2-SQL and ADO.NET Entity Framework can't do it all for you, and
sometimes you need to take complete control with the tools like anything
else and do it yourself.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top