Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EF Core code-based model .. using a Data Dictionary approach ? #1370

Closed
awbmansour opened this issue Jan 8, 2015 · 5 comments
Closed

EF Core code-based model .. using a Data Dictionary approach ? #1370

awbmansour opened this issue Jan 8, 2015 · 5 comments
Assignees
Milestone

Comments

@awbmansour
Copy link

To explain what this is, consider the fact that if we have something like "Customer ID" property that is repeated some 40 times in 40 different model entities, that all refer to the same physical meaning, ie sharing the same common attributes such as Type, Display Format, Display Label, Validation, etc., then with a Data Dictionary approach this Property is defined Once with all its related attributes and then referred to as many as required in the model entities without the need to redefine the Attributes in each entity model file.

As it is now, we copy the Property with all its Attributes to all the Model files that need to have it, and this makes maintenance of the Model a nightmare each time we need to adjust, correct, or change an attribute of a property, we need to inspect all ViewModels and Models to see where else this property is mentioned.

The idea of Data Dictionary based development is not new (in the 1990's of object oriented 4GL development) proved to be a very productive and clean development environments.

Just a humbled thought I wanted to share.

@rowanmiller rowanmiller added this to the Discussions milestone Jan 9, 2015
@rowanmiller rowanmiller self-assigned this Jan 9, 2015
@rowanmiller
Copy link
Contributor

@awbmansour could you elaborate a little more on the code you want to write. Do you want to still have CLR classes for each entity and just apply the same configuration to every CustomerId property? Or do you not want strongly typed classes and have more of a property bag (Dictionary<string, object>) approach?

@awbmansour
Copy link
Author

Dear Rowan,

Thanks a lot for entertaining my humbled suggestion.

My proposal is to have it in an object oriented way, with inheritance, so
on a context level we have overall definitions that are global to the
context, which can be used in any entity class, and optionally in an entity
class the attributes can be altered or redefined.

Assume that the dictionary associated with the context "mycontext" will be
defined in a mycontext_globaldefs.cs file :

mycontext_globaldefs.cs would contain the properties that would be used
commonly or repeatedly in a context with one or more of the attributes that
can be assigned to such properties :

[DisplayFormat(....)]
[DataType(....)]
[Display(...)]

Guid customer_id;

[DisplayFormat(....)]
[DataType(....)]
[Display(...)]
[StringLength(....)]

string customer_name;

In the individual entity classes, we will use these common properties along
with other singular properties which would not justify/warrant the use of a
common/global definition:

in customer.cs entity class file :

namespace MyApp.Models
{
public class customer
{
[Key]
[Required(......)]
public customer_id { get; set; }

    [Required(......)]
    public customer_name { get; set; }

  }

}

In another class (eg, prioritycustomer.cs), where the property will be
used, except one attribute (in the example, the Display attribute) that
needs redefinition, and other attribute that is not needed (in the example,
Required not needed for Customer Name)

in prioritycustomer.cs entity class file :

namespace MyApp.Models
{
public class prioritycustomer
{
[Key]
[Required(......)]
[Display(...)]
public customer_id { get; set; }

    public customer_name { get; set; }

  }

}

I hope I answered your kind question,

Best Regards

Adel

On Sat, Jan 10, 2015 at 1:32 AM, Rowan Miller [email protected]
wrote:

@awbmansour https://github.com/awbmansour could you elaborate a little
more on the code you want to write. Do you want to still have CLR classes
for each entity and just apply the same configuration to every CustomerId
property? Or do you not want strongly typed classes and have more of a
property bag (Dictionary) approach?


Reply to this email directly or view it on GitHub
#1370 (comment)
.

Thanks and Best Regards

Adel Mansour
Director

simplerApps Software Solutions Ltd.
www.simplerapps.com
[email protected]

mobile | viber | whatsapp : +20 122 3987214

@rowanmiller
Copy link
Contributor

@awbmansour - This can be achieved in EF6 using bulk configuration (a.k.a custom conventions).

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    modelBuilder
        .Properties<string>()
        .Where(p => p.Name == "customer_name")
        .Configure(p => p.HasMaxLength(200).IsUnicode(true));

}

Of course, if you wanted to parse some other format (such as the globaldefs.cs class you mentioned) and dynamically create conventions based on that it would be possible.

We'll have something similar in EF7 too, tracked by #214.

@awbmansour
Copy link
Author

Wow .. this is awesome. I will need to learn more on this.

Thanks a lot for your care and time during your busy schedule.
On Jan 13, 2015 12:29 AM, "Rowan Miller" [email protected] wrote:

@awbmansour https://github.com/awbmansour - This can be achieved in EF6
using bulk configuration (a.k.a custom conventions).

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder
.Properties()
.Where(p => p.Name == "customer_name")
.Configure(p => p.HasMaxLength(200).IsUnicode(true));

}

Of course, if you wanted to parse some other format (such as the
globaldefs.cs class you mentioned) and dynamically create conventions based
on that it would be possible.

We'll have something similar in EF7 too, tracked by #214
#214.


Reply to this email directly or view it on GitHub
#1370 (comment)
.

@rowanmiller
Copy link
Contributor

Closing out this issue now, feel free to re-open if you have further questions 😄

@divega divega changed the title EF7 code-based model .. using a Data Dictionary approach ? EF Core code-based model .. using a Data Dictionary approach ? Feb 26, 2018
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants