4 Replies - 1476 Views - Last Post: 16 April 2013 - 12:12 PM Rate Topic: -----

#1 johnyjj2  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 24-July 09

Using list in "code first" (Entity Framework)

Posted 14 April 2013 - 12:12 PM

Hello,

I have started learning Entity Framework (code first) because I need to use it in my current project.

I could notice that most of the tutorials focus on simple classes.

However, I need something a little bit more complex because I cannot know list of values before execution. Those are added to the list during execution.

This is why I would like to know, before proceeding, if it is possible to add something like this to DB with EF:

                public class EntityStringColumn
                {
                        string ParameterName { get; set; }
                        string ParameterValue { get; set; }
                }
 
                public class EntityDoubleColumn
                {
                        string ParameterName { get; set; }
                        double ParameterValue { get; set; }
                }
 
                public class EntityData
                {
                        List<EntityStringColumn> EntityStringColumns { get; set; }
                        List<EntityDoubleColumn> EntityDoubleColumns { get; set; }
                        public EntityData()
                        {
                                EntityStringColumns = new List<EntityStringColumn>();
                                EntityDoubleColumns = new List<EntityDoubleColumn>();
                        }
                }


If not, I would be greatful to hear some advices how to redesign it. Or if it is OK, what should I focus on? Do I need ICollection instead of List or is it optional and I can use List?

I have also noticed that some people use System.ComponentModel.DataAnnotations and System.Transactions in their tutorials. I assume I do not need these for this simple task.

Regards!

Is This A Good Question/Topic? 0
  • +

Replies To: Using list in "code first" (Entity Framework)

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3552
  • View blog
  • Posts: 11,010
  • Joined: 05-May 12

Re: Using list in "code first" (Entity Framework)

Posted 14 April 2013 - 03:04 PM

The point of the entity framework is that you define your objects and it'll somehow map it into a relational database's fixed record formats. Currently what it looks like you are doing above is that you are reinventing a record without fixed fields in your class. I believe that what you have above will work, but it may not be the most efficient relational database.

If you really need that kind of data structure where the fields are not fixed, have you considered using a key-value pair database instead of a relational database?
Was This Post Helpful? 1
  • +
  • -

#3 johnyjj2  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 24-July 09

Re: Using list in "code first" (Entity Framework)

Posted 14 April 2013 - 05:17 PM

Thanks for your answer,

what I have found was that it did not work because I had to add reference to "C:\Program Files (x86)\Microsoft Web Tools\Packages\EntityFramework.5.0.0\lib\net40\EntityFramework.dll", not only "using System.Data.Entity". I also added DbContext to first line as:
public class EntityData : DbContext

Now it builds and I am going to check if I can add values to database.

I have found that I need to use reference to EntityFramework.dll somewhere on google and I have found it in my disc in the above directory. I just wonder if I really need EntityFramework 5.0. I have reference to System.Data.Entity in its v4.0.30319. I have found that several things should be easier in v4.1. I have installed EntityFramework41.exe, however I could not install EF4FeatureCTP4.exe (do I really need it?) because of error:

Quote

Microsoft ADO.NET Entity Framework Feature CTP 4
This application requires .NET Framework 4.0 Client Profile RTM. Please install the .NET Framework then tun this installer again.


I have framework 4.0. For example I can find this directory: C:\Windows\Microsoft.NET\Framework\v4.0.30319. However, in C:\Program Files\Reference Assemblies\Microsoft\Framework and C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework I can find only v3.0 and v3.5 directories.

I don't really know if I should create new forum thread with the above issues but as my topic says about "using Entity Framework" and references to correct libraries and proper environment configuration is essential for that, I have decided to post it here.

Back to main topic, what I really want to do is to enable end user to install my application on his or her computer without need to spend really much time on configuring the environment. So I think this goal can be accomplished with .NET 4.0 and EF 4.0 or 4.1 (this is why reference to "EntityFramework.5.0.0\lib\net40\EntityFramework.dll" worries me).

Quote

If you really need that kind of data structure where the fields are not fixed, have you considered using a key-value pair database instead of a relational database?


In fact I have not considered it but it looks like it may be good idea. However, I would need to find something more about this topic. Can I do it with Entity Framework as well?

At first, I want to focus on simple architecture of my application, just to have it finished, as logics (algorithmical part) connected with data being processed is somehow complex. I want this architecture to allow me to change database connection in the future if I will decide that it works too slowly or occupies too much disc space. But for now I would go with simple solution and I am not sure if writing code that will use key-value pair database is simple enough as I am familiar only with relational databases.

Regards!
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3552
  • View blog
  • Posts: 11,010
  • Joined: 05-May 12

Re: Using list in "code first" (Entity Framework)

Posted 14 April 2013 - 06:12 PM

The CTP in the file/product name means Consumer Technical Preview. I'm not sure that is what you want to ship your "production" code with. You will want tho official released version of 4.1 if you really want to use 4.1: http://www.microsoft...ls.aspx?id=8363

I feel that you'll still have the same problem with Entity Framework 4.1. Your users will still have to download and install it.
Was This Post Helpful? 1
  • +
  • -

#5 johnyjj2  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 24-July 09

Re: Using list in "code first" (Entity Framework)

Posted 16 April 2013 - 12:12 PM

Thanks a lot for your answer!

I have reconsidered my decision and it looks like it is worth to use non-relational database.

At first I thought about MongoDB but I guess that's not the best choice.I have found here there are several different groups of NoSQL DBs: Key/Value (Redis, Tokyo Cabinet, Memcached), ColumnFamily (Cassandra, HBase), Document (MongoDB, CouchDB).

From what I can see here it should be OK to use Cassandra, as every row contains many columns, that are not defined before I need to create new database, there can be any number of columns and data is available by indicating which [1] database (table) I need, [2] keys of rows (in my case it can be index but I think it is much more possible to search with indicating that value of one column equals to abc and the value of second column equals to xyz, where all combinations of values from several columns must be unique and values from other columns are results from some calculations).

However, from what I have found it looks like Cassandra is ColumnFamily and you say about key/value DB.

I have found there are several ways of accessing it from C#, i.e. Thrift, FluentCassandra, cassandra-sharp, Cassandraemon and Aquiles. I just wonder which one of these would be the best. I am looking for the simplest in use and the best in support choice.

I am a little bit worried that Cassandra uses Java. I have heard that in last releases of Java there are unexpectidely many bugs (much more than in previous versions of Java). However, I thought about deploing my app in VPS or Windows Azure, so it should be possible to protect data just by configuring environment properly, and maybe with encrypting data being stored.

Later I will need to write some kind of component for data visualization and I thought about using WPF for that, as I need to dynamically change the structure of data being presented. However, I will consider the way of data visualization in details later.

Regards!

This post has been edited by johnyjj2: 16 April 2013 - 12:14 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1