Re: VS2008: How to access properties of a table in O/R designer

  • From: "Varun Khosla" <varun.lists@xxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Sun, 15 Jun 2008 02:12:45 -0800

Glad you ask Rick!
Well, I'm actually doing these sorts of things with LINQ these days.
Joining (inner/outer(left/right)) is fully supported with keywords
like join, group join and implicit joining. You just need to peruse
the link page I provided in my previous mail. About transaction, ya
it's too, but I got little on it on msdn and I had to google it to
find how actually it can be done. bare with me and I'll explain it to
you.

The screen I was developing for my project had data to be
fetched/inserted into multiple (three to be exact) tables, the fun
part was that, there's a delete command requiring data associated with
the key (selected item) to be deleted from all the three tables, the
key was primary in the main table and foreign in the other two thus
required a correct sequence to be followed. But later I found that
cascade style deletion was not supported by linq data context. I had
limited options with me, I could seperate the deletion into two parts
(deleting the data first from the child tables then from the main
table). Moreover, an attached condition was also there that if any
fourth table (not directly associated with my screen) contained data
related to the selected key, the data shouldn't be deleted from the
main table (so as from other two child tables), that wasn't a problem
coz data context handles relational objects on its own, but in case of
seperation, I had to manually restore the two child tables if there's
an error deleting the same from the main one. Now here comes
transaction role.
system.data.common provides a DbTransaction class which is also
implemented by data context in the property named transaction. But if
one is using this mechanism (of explicit transaction) one has to
explicitly commit all transactions (dataContext supports implicit
transaction when there's no explicit transaction specified).

I can write codelines explaining you exactly how it can be done if you require.

HTH



On 6/14/08, Ricks Place <OFBGMail@xxxxxxxxx> wrote:
> Thanks for the write-up Varun. I will take a further look at coding syntax
> for LINQ. Have you done any cross table or multi-table queries and inserts
> using transactions or anything that would require accessing multiple tables?
> I am thinking of something llike an insert running as a transaction
> requireing 2 tables to be updated or a rollback to occur.Also, have you
> tried any joins on multiple tables?
> Rick Farmington Mich. USA
> ----- Original Message -----
> From: "Varun Khosla" <varun.lists@xxxxxxxxx>
> To: <programmingblind@xxxxxxxxxxxxx>
> Sent: Saturday, June 14, 2008 4:31 AM
> Subject: Re: VS2008: How to access properties of a table in O/R designer
>
>
>> Hi Rick,
>> See below why you may find LINQ more easier than ADO.net.
>>
>>
>> Language-Integrated Query (LINQ)
>>
>> Language-Integrated Query (LINQ) is a set of features in Visual Studio
>> 2008 that extends powerful query capabilities to the language syntax
>> of C# and Visual Basic. LINQ introduces standard, easily-learned
>> patterns for querying and updating data, and the technology can be
>> extended to support potentially any kind of data store. Visual Studio
>> 2008 includes LINQ provider assemblies that enable the use of LINQ
>> with .NET Framework collections, SQL Server databases, ADO.NET
>> Datasets, and XML documents.
>>
>>
>> Language-Integrated Query (LINQ) is a groundbreaking innovation in
>> Visual Studio 2008 and the .NET Framework version 3.5 that bridges the
>> gap between the world of objects and the world of data.
>>
>> Traditionally, queries against data are expressed as simple strings
>> without type checking at compile time or IntelliSense support.
>> Furthermore, you have to learn a different query language for each
>> type of data source: SQL databases, XML documents, various Web
>> services, and so on. LINQ makes a query a first-class language
>> construct in C# and Visual Basic. You write queries against strongly
>> typed collections of objects by using language keywords and familiar
>> operators. The following illustration shows a partially-completed LINQ
>> query against a SQL Server database in C# with full type checking and
>> IntelliSense support.
>>
>>
>> In Visual Studio you can write LINQ queries in Visual Basic or C# with
>> SQL Server databases, XML documents, ADO.NET Datasets, and any
>> collection of objects that supports IEnumerable or the generic
>> IEnumerable<(Of <(T>)>) interface. LINQ support for the ADO.NET Entity
>> Framework is also planned, and LINQ providers are being written by
>> third parties for many Web services and other database
>> implementations.
>>
>> You can use LINQ queries in new projects, or alongside non-LINQ
>> queries in existing projects. The only requirement is that the project
>> target version 3.5 of the .NET Framework.
>>
>> http://msdn.microsoft.com/en-us/library/bb397897.aspx
>>
>> You can even now query variables as if they are database objects! :-)
>>
>>
>> On 6/12/08, Ricks Place <OFBGMail@xxxxxxxxx> wrote:
>>> Man! That looks way diferent than Ado or even regular old Select
>>> statements!
>>> That problem with the ReadOnly is the one I have run up against. It is
>>> the
>>> same in DataSet methodology. We are working with PreDefined rows in the
>>> schema so any changes must be applied to an instance of the PreDefined
>>> row
>>> and if we select only 2 columns and tried to update them the other
>>> columns
>>> would not have any values because they were not a part of the original
>>> select statement. Have you found Linq any easier than Ado? It looks
>>> verbose.
>>> Rick USA
>>> ----- Original Message -----
>>> From: "Varun Khosla" <varun.lists@xxxxxxxxx>
>>> To: <programmingblind@xxxxxxxxxxxxx>
>>> Sent: Wednesday, June 11, 2008 12:47 AM
>>> Subject: Re: VS2008: How to access properties of a table in O/R designer
>>>
>>>
>>>> Hi Ricks,
>>>> In linq when we query the database like this:
>>>> dim resultRow = (from tableVar in dataContext.TableName where
>>>> tableVar.key = matchingKeyVar select tableVar).take(1).single()
>>>>
>>>> the resultRow variable is filled up with first row resulting from the
>>>> where condition. Now suppose the queried table has 15 columns, and we
>>>> want to update the value of column5&6, we can do that like this:
>>>> resultRow.column5 = "some value"
>>>> resultRow.column6 = "some another value"
>>>> And call submit changes like this:
>>>> dataContext.SubmitChanges()
>>>> It will update those two columns. since resultRow contained values of
>>>> all the 15 columns, we don't need to specify the value of each but
>>>> only those which we want to update.
>>>> But if you had specified a select statement in the linq query like this:
>>>> dim resultRow = (from tableVar in dataContext.TableName where
>>>> tableVar.key = matchingKeyVar select tableVar.column5,
>>>> tableVar.column6).take(1).single()
>>>> This query will result in only two columns being members of resultRow,
>>>> but as I have seen, these columns are read-only and you cannot change
>>>> their value.
>>>>
>>>> HTH
>>>>
>>>> On 6/8/08, Ricks Place <OFBGMail@xxxxxxxxx> wrote:
>>>>> Hi Guys:
>>>>> Along these lines:
>>>>> When I use a DataTable, DataSet, I get Rows on any select. I can limit
>>>>> the
>>>>> data returned to a couple of columns but it seems I have to provide
>>>>> values
>>>>> for an entire row or the values are messed up during an update. I don't
>>>>> think I can just set and update a couple of columns using the DataSet
>>>>> Update
>>>>> function. Is this the case with Linq? Can you just Select a couple of
>>>>> columns, set them and then apply an update for them or will that tip
>>>>> other
>>>>> columns in the original row?
>>>>> I hope I explained this well enough to understand and my understanding
>>>>> is
>>>>> correct. I had problems like this some time ago so always just read
>>>>> entire
>>>>> rows, update whatever columns I want then ReWrite the entire row. This
>>>>> is,
>>>>> of course, pretty inefficient and I even had to write a TableAdapter
>>>>> extension to avoid Optimistic Concurrency for a particular update since
>>>>> it
>>>>> was so blasted slow and unnessisary for the particular update.
>>>>> Anyway, while on the Linq topic I thought I would ask in case someone
>>>>> has
>>>>> had experience with this situation.
>>>>> Rick Farmington Mich. USA
>>>>> If you knowal Message -----
>>>>> From: "Varun Khosla" <varun.lists@xxxxxxxxx>
>>>>> To: <programmingblind@xxxxxxxxxxxxx>
>>>>> Sent: Sunday, June 08, 2008 3:10 AM
>>>>> Subject: Re: VS2008: How to access properties of a table in O/R
>>>>> designer
>>>>>
>>>>>
>>>>>> By the way, I've found an alternative for this. Locate the table in
>>>>>> the designer window, press shortcut key, open add sub-menu, click
>>>>>> property - it will take you to the list of the columns for that table
>>>>>> focussing an edit box forcing you to specify a name for the new
>>>>>> property. Pressing the shift+tab creates a new property with the
>>>>>> default name property1, since it's not required one can delete it by
>>>>>> selecting it in the listbox and pressing the dell key.
>>>>>>
>>>>>> I know that this is not the right way to go about it, but this is the
>>>>>> only way I'm able to know to go about it. (smile)
>>>>>>
>>>>>>
>>>>>> On 6/7/08, Varun Khosla <varun.lists@xxxxxxxxx> wrote:
>>>>>>> P.P.S. is additional postscript
>>>>>>>
>>>>>>> On 6/1/08, Chris Hallsworth <christopherhallsworth71@xxxxxxxxxxxxxx>
>>>>>>> wrote:
>>>>>>>> Hi what's PPS? I've heard of PS but not PPS? Thanks and sorry for my
>>>>>>>> ignorance.
>>>>>>>> --
>>>>>>>> Chris Hallsworth
>>>>>>>>   ----- Original Message -----
>>>>>>>>   From: Varun Khosla
>>>>>>>>   To: programmingblind@xxxxxxxxxxxxx
>>>>>>>>   Sent: Monday, June 02, 2008 8:13 AM
>>>>>>>>   Subject: VS2008: How to access properties of a table in O/R
>>>>>>>> designer
>>>>>>>>
>>>>>>>>
>>>>>>>>   Hello listers,
>>>>>>>>   Has anybody worked on VS2008? It has new feature called LINQ
>>>>>>>> (Language-Integrated Query) designed to further increased the
>>>>>>>> speed/object
>>>>>>>> orientation of working with database. It has added an O/R designer
>>>>>>>> for
>>>>>>>> this
>>>>>>>> purpose. User can drag-drop tables from server explorer to the
>>>>>>>> designer
>>>>>>>> to
>>>>>>>> create a data context which is the focle point of LINQ.
>>>>>>>> Dragging/dropping
>>>>>>>> part is okay because Jaws has a shortcut key for this purpose. The
>>>>>>>> problem
>>>>>>>> I'm facing is how to access properties of the table object (don't
>>>>>>>> confuse
>>>>>>>> properties here with the general properties of any components such
>>>>>>>> as
>>>>>>>> Name
>>>>>>>> which can be accessed via f4 in O/R as well, but with the properties
>>>>>>>> here
>>>>>>>> I
>>>>>>>> mean by columns of a table) so that I can delete specific columns
>>>>>>>> that
>>>>>>>>
>>>>>>>> I
>>>>>>>> don't require (only from the table class of O/R designer and not
>>>>>>>> from
>>>>>>>> the
>>>>>>>> database).
>>>>>>>>
>>>>>>>>   Has anybody gotten an idea as to how it can be done?
>>>>>>>>
>>>>>>>>   P.S. I've not been able to find a shortcut key for this anywhere
>>>>>>>> on
>>>>>>>> the
>>>>>>>> net.
>>>>>>>>   P.P.S. Sighted folks can access it with the mouse, but there's no
>>>>>>>> text
>>>>>>>> written at that point to make jaws cursor do the job.
>>>>>>>>
>>>>>>>>   Thanks
>>>>>>>>
>>>>>>>>   --
>>>>>>>>   Varun
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> Varun
>>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> Varun
>>>>>> __________
>>>>>> View the list's information and change your settings at
>>>>>> //www.freelists.org/list/programmingblind
>>>>>>
>>>>>
>>>>> __________
>>>>> View the list's information and change your settings at
>>>>> //www.freelists.org/list/programmingblind
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> Varun
>>>> __________
>>>> View the list's information and change your settings at
>>>> //www.freelists.org/list/programmingblind
>>>>
>>>
>>> __________
>>> View the list's information and change your settings at
>>> //www.freelists.org/list/programmingblind
>>>
>>>
>>
>>
>> --
>> Varun
>> __________
>> View the list's information and change your settings at
>> //www.freelists.org/list/programmingblind
>
> __________
> View the list's information and change your settings at
> //www.freelists.org/list/programmingblind
>
>


-- 
Varun
__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: