Skip to content

Existing MsSql Views in DbFirst #120

Description

@sapatag

In Vita 1.x vdbtool scripted the existing MsSql views, and they worked as expected.
How can I script/use them in 3.x?

Another question:
In 1.x I used lots of [NoColumn] fields from other Entity types. 3.x does not allows it. Is it intentional?
For the latter I made the folloing quick fix:

private void BuildEntityMembers() {
  foreach (var entInfo in Model.Entities) {
    bool isTable = entInfo.Kind == EntityKind.Table; 
    var props = entInfo.EntityType.GetAllProperties();
    EntityMemberInfo member; 
    foreach (var prop in props) {
      EntityMemberKind kind;
      if (TryGetMemberKind(entInfo, prop, out kind)) {
        var memberAttrs = prop.GetAllAttributes();     //Quick fix
        if (memberAttrs.Any(a=>a is NoColumnAttribute))//
          kind = EntityMemberKind.Transient;           //
        member = new EntityMemberInfo(entInfo, kind, prop); //member is added to EntityInfo.Members automatically
        member.Size = member.GetDefaultMemberSize();
        // if it is table, or prop is declared on THIS entity (not inherited), take all attributes
        if(isTable || prop.DeclaringType == entInfo.EntityType)
          member.Attributes.AddRange(memberAttrs);
        else {
          // for inherited members on views we take only OneToMany and ManyToMany attributes; 
          //  - we want to allow list properties on view entities (see vFictionBook view in Sample book store)
          var listAttrs = memberAttrs.Where(a => a is ManyToManyAttribute || a is OneToManyAttribute).ToList();
          member.Attributes.AddRange(listAttrs); 
        }
      } //else - (kind not found) - do nothing, the TryGetMemberKind should have logged the message
    }
  }//foreach entType
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions