LLBLGen
(1)
LINQ
(1)
DropDownItems.DataSource
(1)
TlkpCompanyTypeID
(1)
CreateUser
(1)
GetTable
(1)
TlkpColorID
(1)
Database
(1)
LINQ inheritance problem
Asked By Leo Seccia
06-May-08 08:30 AM

Hello everyone,
I have a c# project with a sql server database.
I have a number of lookup tables in my database which I successfully managed
to import into my LINQ dataclasses.
eg.
Table: tlkpColor
(PK) tlkpColorID
strDescription
dtmCreate
strCreateUser
Table: tlkpCompanyType
(PK) tlkpCompanyTypeID
strDescription
dtmCreate
strCreateUser
an so on...
I would like to create a generic lookup object to inherit from for my lookup
objects generated from the tables. I have tried to create a generic object
and setting discriminator property to implement inheritance as seen on some
tutorials on the net but I'm just not having any luck (and I have spent a
long time on this).
eg.
Table: tlkpGeneric
strDescription
dtmCreate
strCreateUser
Table: tlkpColor
(PK) tlkpColorID
Table: tlkpCompanyType
(PK) tlkpCompanyTypeID
etc...
I've also tried other combinations (eg. overring properties in subclasses)
Essentially, I would like to union all my lookup tables into one generic one
with a composite primary key (id + type/discriminator value) but using
inheritance.
Am I tackling this the right way?
I hope I am making sense, sorry if I am not. Please let me know if I need to
clarify anything.
Thank in advance,
Leo
LINQ inheritance problem
Asked By Frans Bouma [C# MVP]
07-May-08 03:43 AM

Tip: don't prefix table field names with type descriptions. Also don't
prefix table names with 'tbl' or other prefixes: The entity description
itself should be enough about what it represents.
I assume you're talking about Linq to Sql. Linq to Sql only supports
inheritance on 1 table/view, thus the complete inheritance hierarchy is
mapped onto the same table/view.
That aside, I would advice against inheritance for this scenario, as
inheritance should only be used if you are adding specialization fields
to an entity. E.g. you have a base table 'Animal' and you have subtypes
'Dog', 'Fish' etc.
Lookup data is just that: a key and some textdata mostly, mostly
they're constant and there's NO inheritance involved at all,as the
subtypes aren't really extending the supertype.
this requires a table per type, which isn't supported by Linq to Sql.
It is by other o/r mappers though.
However, as I said above, it's not useful here. I understand that you
might think that the fields 'Description', 'CreateUser' and 'Create' are
shared among more than 1 type and therefore could benefit from
inheritance, but you also have to understand that if you have 1 table
per type, performance degrades because you have to join the two tables
together.
You shouldn't do this. Don't take this the wrong way, but you're making
a bunch of basic datamodel mistakes: why would you choose to create a
compound PK if 'id' is already unique?
An entity is identified by a unique attribute (field). This can be any
field in the entity itself or by an artificial one added for this
purpose, e.g. 'id'.
The discriminator field has no place in this PK, as it adds NOTHING for
the identification for the entity instance (table row): 'id' is enough.
Please read some basic relational modeling papers. I can recommend this
paper http://www.orm.net/pdf/ORMwhitePaper.pdf and other papers on
http://www.orm.net
FB
--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Hello Frans,First of all, I would like to thank you for the reply.
Asked By Leo Seccia
07-May-08 05:17 AM

Hello Frans,
First of all, I would like to thank you for the reply. Here are a few notes.
I know exactly what you mean - I really don't like prefixes and I don't find
them useful.
Unfortunately this part is not up to me and the db already exist.
I agree with you all the way here, inheritance is definately not going to
help in this scenario and it would be a very bad idea to us it.
The id in the union would not be unique anymore...
Anyway, you are right I shouldn't do this and I am not going to (for obvious
reasons).
I guess it was a really bad way to explain what I want to do.
Basically, I need a way to have a generic class to access all lookup data
access classes in a uniform way and as I am new to LINQ I overlooked at what
inheritance should actually be used for and I explained very badly what I
needed to achieve. Sorry.
Here is the full picture, from an higher level:
We have a very large set of lookup lists that we would like to view, filter,
edit, modify, delete records using one form and common code. Using weakly
typed objects is a bit of a nightmare (eg. from GetTable(Type)) so we
thought, if we have one generic object to cast to and perform linq
operations against, it would be great.
And this is how it all started...
I am sorry if the post appears dumb, but it is our first real linq project
and I'm trying to figure out how to do things.
Thank you for the links, definately interesting...
Regards,
LS
Hello everyone,I finally solved my problem... All I needed was an interface.
Asked By Leo Seccia
07-May-08 12:17 PM
Hello everyone,
I finally solved my problem... All I needed was an interface. ;-)
It works!!!
eg.
var gdi = dc.GetTable(theType).Cast<IDropDownItem>();
dropDownItems.DataSource = gdi.Where(a => a.bObsolete == false);
NB. Using GetTable(type) rather than GetTable<TEntity>() returns the weakly
typed version... Therefore casting is needed...


NET Framework LINQ inheritance problem Hello everyone, I have a c# project with my database which I successfully managed to import into my LINQ dataclasses. eg. Table: tlkpColor (PK) tlkpColorID strDescription dtmCreate strCreateUser Table about what it represents. I assume you're talking about Linq to Sql. Linq to Sql only supports inheritance on 1 table / view, thus requires a table per type, which isn't supported by Linq to Sql. It is by other o / r mappers though papers on http: / / www.orm.net FB - - - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - Lead developer of LLBLGen Pro, the productive O / R mapper for .NET LLBLGen Pro website: http: / / www.llblgen.com My .NET blog: http: / / weblogs.asp.net / fbouma Microsoft in a uniform way and as I am new to LINQ I overlooked at what inheritance should actually be used for we have one generic object to cast to and perform linq operations against, it would be great. And this is how
NET Framework LINQ DataSource, Where Parameters, ASP.NET I know that if I want to use a linq query instead of a simple "select" query that I can override the LINQ data source selecting event. I, also, know that I can Changed then I can set the WhereParameter of the Child linq atasource and databind and that works. But, what if I wanted to call instead a custom query method or write LINQ? Is this a bad idea. My goal would be to use LINQ queries so that I do not have any embedded strings have to pull the datakey out of the object. keywords: LINQ, DataSource, , Where, Parameters, , ASP.NET description: I know that if I want to use a linq query instead of a simple select query that I can
NET Framework Linq an Datasource mit großer Datenmenge binden Hallo zusammen, ich habe das Problem Tabelle mit sehr vielen Einträgen (ca. 70.000) an eine Linq-Datasource binden will. Das funktioniert auch prima, dauert nur ewig !!! Damit den nächsten / vorgerigen etc. automatisch Datensatz anzuzeigen, da in der Datasource dann nur ein Datensatz ist. Hat jemand dafür eine Lösung gehofft, das es eine elegantere Möglichkeit gibt. Gruss Alex keywords: Linq, an, Datasource, mit, großer, Datenmenge, binden description: Hallo zusammen, ich habe das Tabelle mit sehr vielen Einträgen (ca. 70.000) an eine Linq-Datasource binden will. Das funktioniert
NET Framework populate a DataSet via a LINQ query (Linq to XML) Is there a way to populate a DataSet via a LINQ query? (Linq to XML) Instead of; DataSet ds = new DataSet(); ds.ReadXml myfile.xml, XmlReadMode.InferTypedSchema); dataGridView1.DataSource = ds.DefaultViewManager; dataGridView1.DataMember = "myNode"; Anthony You use a Linq-2-XML query and just bind the Linq query results to the control. You can do that. You do not need a dataset. How can i bind the Linq query results to the control ? Anthony it is in the Value }; All you have to do here is this. dataGridView1.DataSource = q; I think it will bind to the List<T objects You may look into BindingSource control still using BS.Datasource = q; [ . . ] This does not work Tried this: bindingSource1.DataSource = q
NET Framework constains or linq linq on objects. . . want to find if the object exist in field01 = = type && r.field02 = = id) return true; } return false; versus Linq List <myClass> qq = (from r in SecondaryIds where r.field01 obj in collection) 2. how do get collection count from linq or can I set a true variable if found? thanks only problem I may expect is if my sample of linq is ran on a very large database, it might ran might throw? raulavi, Well, it depends. If this is a LINQ to SQL query, then the query is composed and sent explanation. . .right on the nail Nicholas, thanks keywords: constains, or, linq description: linq on objects. . . want to find if the object exist in
NET Framework DropDownList Binding to LINQ DataSource I was playing around with the LINQtoSQL and found an orderby c.CompanyName select new { c.CompanyName, c.CustomerID }; ddCustomers.DataSource = customers; ddCustomers.DataTextField = "CompanyName"; ddCustomers.DataValueField = "CustomerID"; ddCustomers.DataBind(); ddCustomers I need the CustomerID to populate a grid from another linq query but it doesnt matter which item in the dropdownlist R. Longnecker http: / / blog.tiredstudent.com keywords: DropDownList, Binding, to, LINQ, DataSource description: I was playing around with the LINQtoSQL and found
NET Framework SQL -> LinQ , LinQ" / > Hallo alle zusammen!!! Ich habe den folgenden Code hier schon ein (für mich) ziemlich komplexes SQL Statement & versuche daraus eine LinQ zu machen (was für mich noch sehr kryptisch wirkt. . .) Das Code noch werfen. . . . DANKE euch jetzt schon mal allen!!!! PS: - LinQ to DataSet!!!!!!!!!!!!!!!!!!!!!!!!!! Schönen Nachmittag. Also, ich bin schon einen Group By - Wie muss ich das anwenden? 2) Bei Folgendem LinQ: Now > = Type.Field(Of Date?)("lieferbar_ab") And _ Now < = Type
NET Framework "LINQ to SQL" and "LINQ to Entity" Hi I do not know these tools ("LINQ to SQL" and "LINQ to Entity"), and I would like some good resources to them. They seem very similar - but from what I gather, LINQ to Entity is more complex, and more of an OR / M tool than LINQ to SQL is. Which would be the best to concentrate up against NHibernate? Thank you, Peter And is it called "LINQ to Enitity" or "LINQ to Entities"? keywords: "LINQ, to, SQL", and, "LINQ, to, Entity" description: Hi I do not know these tools