MCPcopy Create free account
hub / github.com/Houseofmvps/codesight / extractEntityFrameworkModels

Function extractEntityFrameworkModels

src/ast/extract-csharp.ts:111–167  ·  view source on GitHub ↗
(
  _filePath: string,
  content: string
)

Source from the content-addressed store, hash-verified

109// ─── Entity Framework models ───────────────────────────────────────────────
110
111export function extractEntityFrameworkModels(
112 _filePath: string,
113 content: string
114): SchemaModel[] {
115 const models: SchemaModel[] = [];
116
117 // Find DbContext subclass
118 if (
119 !content.includes("DbContext") &&
120 !content.includes("DbSet<")
121 ) {
122 return models;
123 }
124
125 // Extract each DbSet<ModelName> property
126 const dbSetPattern = /DbSet\s*<\s*(\w+)\s*>/g;
127 const modelNames = new Set<string>();
128 let m: RegExpExecArray | null;
129 while ((m = dbSetPattern.exec(content)) !== null) {
130 modelNames.add(m[1]);
131 }
132
133 if (modelNames.size === 0) return models;
134
135 // For each model name, try to find class definition in same file
136 for (const modelName of modelNames) {
137 const classPattern = new RegExp(
138 `class\\s+${modelName}\\s*(?::\\s*[\\w<>, ]+)?\\s*\\{([\\s\\S]*?)\\n\\s*\\}`,
139 "m"
140 );
141 const classMatch = content.match(classPattern);
142
143 if (classMatch) {
144 const body = classMatch[1];
145 const fields = extractCSharpProperties(body);
146 if (fields.length > 0) {
147 models.push({
148 name: modelName,
149 fields,
150 relations: extractCSharpRelations(body),
151 orm: "entity-framework",
152 });
153 continue;
154 }
155 }
156
157 // Model class not in this file — just record the name from DbSet
158 models.push({
159 name: modelName,
160 fields: [],
161 relations: [],
162 orm: "entity-framework",
163 });
164 }
165
166 return models;
167}
168

Callers 1

Calls 2

extractCSharpPropertiesFunction · 0.85
extractCSharpRelationsFunction · 0.85

Tested by

no test coverage detected