Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

class to data

Status
Not open for further replies.

deejayAr

Technical User
Mar 20, 2008
126
US
I'm have classes and need to make data tables as follow
Class 1
public class EventType
{ public String Id { get; private set; }
public int Severity { get; set; }
public EventTypeTemplate Template { get; set; }
public IDictionary<String, String> Params { get; set; }
public EventType(string id)
{ Id = id; Params = new Dictionary<string, string>();}}

And second class
public class EventTypeTemplate
{public String Id { get; private set; }
public int Severity { get; set; }
public String Title { get; set; }
public String Description { get; set; }
public IList<String> Categories { get; private set; }
public IList<String> Queries { get; private set; }
public EventTypeTemplate(string id)
{ Id = id;Categories = new List<string>();
Queries = new List<string>(); } }

For class 1(EventType) I create the table
As table name EventType
Column type
Id string
Severity int
And I don’t know how to enterprate other two property into table column name and type

public EventTypeTemplate Template { get; set; }
public IDictionary<String, String> Params { get; set; }

for second class
I create table name EventTypeTemplate
Column Type
Id string
Severity int
Title string
Description string

But I don’t know how to enterprate follow property into table column name and type

public IList<String> Categories { get; private set; }
public IList<String> Queries { get; private set; }


any help will be appreciated
 
you would need to to map the lists/dictionaries as additional tables. This would introduce three new tables
EventTypeParams (EventTypeId, Key, Value)
EventTypeTemplateCategories (EventTypeTemplateId, Category)
EventTypeTemplateQueries (EventTypeTemplateId, Query)

What you describe is scratching the surface of ORM (object relational mapper). converting relational data to objects and vice versa is not a 1:1 correlation, typically. There are a number of mappers out there. AutoMapper converts object A to object B using naming conventions. AutoMapper isn't technically an ORM, but you can use it as one.

Then you have true ORMs. Nhiberanate, ActiveRecord, LLBL Gen Pro, Entity Framework.

HTH

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
you are right I'm using EF4
do you have some sample that would help me to achieve what I'm doing?

thanks,
 
I'm sure there are plenty of examples on the web. I use NH instead of EF.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
thank you very much for your reply now how to write select statement to find all events and EventTypeParams
and all eventtypetemplate,EventTypeTemplateCategories,EventTypeTemplateQueries

 
well the simplest way is to query for EventType and let lazy loading take care of the rest, however that will lead to performance problems because you have the classic "select n+1" scenario.

to counter that you would need to eager load related entities. This too can lead to a performance problem if you try to select everything in a single database call. you load too much duplicated data thus hindering performance.

the key is to find balance between the size of the results set and the number of database calls.

I know you can fine tune this type of thing with Nhibernate. I'm not sure if EF has this capability or not.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top